vuejs2 - 如何在 vue.js 中从子组件向父组件发出带有 id 的函数
问题描述
我有一个卡片组件和一个房子组件。我想从子组件向父组件发出函数以及 id。我想从内部组件的卡组件调用编辑函数。卡片.vue
<tr class="registrationtable" v-for="valueList in values" v-bind:key="valueList">
<td class="registrationtable" v-for="head in columnHeader" v-bind:key="head">
<span v-if="href.includes(head)">
{{ head }}
<a
v-for="action in actionList"
v-bind:key="action"
v-on:click="methodToCall(valueList[head])"
>{{ action }}</a
></span
>
<span v-else></span>
</td>
</tr>
created() {
this.methodToCall(id);
},
房子.vue
<card :method-to-call="editFunction" />
解决方案
您可以使用this.$emit()
card.vue 模板
<tr class="registrationtable" v-for="valueList in values" v-bind:key="valueList">
<td class="registrationtable" v-for="head in columnHeader" v-bind:key="head">
<span v-if="href.includes(head)">
{{ head }}
<a
v-for="action in actionList"
v-bind:key="action"
v-on:click="methodToCall(valueList[head])"
>{{ action }}</a
></span
>
<span v-else></span>
</td>
</tr>
卡片.vue
methods:{
methodToCall:function(id){
this.$emit('methodToCall', id)
}
}
房子.vue
<card :method-to-call="editFunction" />
推荐阅读
- python - 通过 Python GATT 服务器发送音频
- r - 如何根据连续的行值聚合数据?
- javascript - Autodesk Design Automation“值不能为空。(参数'ForgeConfiguration.ClientId')”
- angular - 元素隐式具有“任何”类型,因为“徽标”类型的表达式不能用于在 Angular 中索引类型“对象”
- javascript - 我可以使用 iframe 或其他技术将 Microsoft Teams 视频会议嵌入我的网站吗?
- highcharts - 避免数据点重叠并在高级可访问的高图中提供相同的工具提示
- node.js - 将查询结果转换为域实体的最佳方法
- python - Python文本换行:我可以根据行中的内容调整最大宽度吗?
- php - PHP 警告 - PHP 启动:无法加载动态库 'imagick.so'
- verilog - 24 小时制代码,出现扇出错误