javascript - 数据未从 Vue.js 中的子组件发送到父组件
问题描述
下面是子组件和父组件。我无法弄清楚我哪里出错了,但我无法将值数据从子组件传递到父组件。请帮我找出哪里出错了。
子组件
<template>
<div>
<v-btn class="red-button" @click.prevent="checkAgent('information')">
Information
</v-btn>
<v-btn class="red-button" @click.prevent="checkAgent('policies')">
Policies
</v-btn>
</div>
</template>
<script>
export default {
data: function () {
return {
}
},
methods: {
checkAgent(value) {
this.$emit('navigate', value);
},
}
};
</script>
父组件
<template>
<v-layout row wrap>
<v-flex xs12 sm12 lg12 >
<div class="account-section">
<Details @navigate="moveTo(value)"/>
</div>
</v-flex>
</v-layout>
</template>
<script>
import Details from 'views/agent/edit.vue';
export default {
components: {
Details,
},
data: function () {
return {
}
},
methods: {
moveTo(value) {
console.log(value)
},
},
};
</script>
解决方案
您应该调用发出的事件处理程序而不在模板中指定参数:
<Details @navigate="moveTo"/>
方法:
methods: {
moveTo(value) {
console.log(value)
},
},
推荐阅读
- java - 单击父窗口时,模态 JDialog 消失
- python - Python嵌套字典理解与if else
- powershell - 从脚本运行时,Connect-PnPOnline URI 无效
- ubuntu - 如何在 Ubuntu 18.04 上为 WeasyPrint 51 安装 Cario 1.16.0
- safari - iOS 中 Safari 上的 TURNS / TURN 协议
- kdb - KDB+/Q:如何创建一个列来增加另一列的唯一值的出现?
- google-apps-script - 有没有办法精确控制谷歌应用程序脚本触发时间?
- jquery - 渲染 rhandsontable 后,日期选择器显示在模态对话框后面
- react-native - 如何修复元素类型无效预期反应原生中的字符串或类/函数错误?
- mysql - docker - mysql 版本 - 如何更新?