vue.js - 将数据从子组件传递到父组件 Vuetify
问题描述
我正在尝试使用 $emit 将数据从子组件传递到父组件,但它不起作用。
这就是我正在做的:
// child component
<v-text-field
@change="function"
v-model="choice1"
label="Choice 1"
></v-text-field>
// Script
metods:{
function(event) {
this.$emit('input', this.choice1); // I tried 'change' at the place of 'input' but with no result too.
},
}
// parent component
<typeQst @change="getRep"></typeQst> // my child component
//script
getRep(value){
console.log(value);
}
解决方案
我看到一些错误:
// child component
<v-text-field
<!-- DO NOT USE FUNCTION AS NAME -->
@change="function"
v-model="choice1"
label="Choice 1"
></v-text-field>
// Script
<!-- Here is Methods not Metods -->
methods:{
<!-- Same as before, change this method name accordingly -->
function(event) {
this.$emit('change', this.choice1); // I tried 'change' at the place of 'input'
but with no result too.
},
}
// parent component
<!-- Here is most probably type-qst not typeQst, camel case get resolved automatically -->
<typeQst @change="getRep"></typeQst> // my child component
<!-- All This part needs to be in the vue export syntax as for the component before: -->
[..]
methods: {
//script
getRep(value){
console.log(value);
}
}
推荐阅读
- node.js - 在节点 js 中导入
- javascript - 使用 document.createElement 测试该元素的 scrollHeight 和 clientHeight 时,值始终为 0
- ubuntu - Ubuntu 终端中 Vim 的边缘未填充颜色方案
- java - 仅当 BufferedReader 中有数据时如何创建文件?
- xml - 使用 xslt 1.0 从多节点 xml 获取特定值
- postgresql - PostGis -> ST_Contains:如何检查表的哪个 BBox 是当前 BBox
- javascript - 在刷新页面上找不到 React js/空白页面
- gradle - 如何在 gradle 复合构建中包含 3 个目录和 2 个可交付成果?
- metadata - 编辑镶木地板文件元数据
- python - 我不断收到此错误:长度不匹配:预期轴有 1 个元素,新值有 5 个元素。我如何解决它?