【发布时间】:2021-12-08 07:21:24
【问题描述】:
我正在与BootstrapVue 合作。
我的 parent.vue 中有一个方法,我将一个值 (this.propsIndex) 传递给我的 child.vue。
现在我想每次在 child.vue 的方法中单击它时都使用这个 value - 但是如何触发我的函数并使其工作?
非常感谢!
如果可能的话,我想避免使用watch
我的父母.vue
<template>
<div v-for="(id, index) in inputs" :key="index">
<b-button @click="deleteViaIndex(index)">Delete</b-button>
<child :indexProps="indexProps" />
</div>
<div>
<b-button @click="addInput()">Add Input</b-button>
</div>
</template>
<script>
methods: {
deleteViaIndex(index) {
this.propsIndex= index;
},
addInput() {
this.inputs.push({})
},
},
data() {
return {
inputs: [{}],
propsIndex: '',
}
}
</script>
我的 child.vue(脚本)
props: ["propsIndex"],
methods: {
deleteViaParentIndex() {
//HERE I WANT TO USE IT EVERY TIME IT WILL BE CLICKED IN MY PARENT.VUE
//BUT FOR NOW IT'S NOT DOING ANYTHING WHEN I CONSOLE.LOG(this.propsIndex)
}
}
【问题讨论】:
标签: javascript vue.js vuejs2 components