我正在尝试与nuxtjs建立儿童与父母之间的交流。这是我的孩子:
<div>
<b-nav-item @click="clicked" :class="{active: active}">{{item.name}}</b-nav-item>
</div>
</template>
<script>
export default {
props: {
item:{
required: true
},
active:{
type: Boolean,
default: false
}
},
methods: {
clicked() {
this.$emit('clicki');
}
},
}
</script>
父母:
<NavigationElement v-for="item in clients" :key="item.id" :item="item" @clicki="showClient" :active="currentClient._id==item._id"><NavigationElement>
</template>
<script>
import NavigationElement from '~/components/NavigationElement.vue'
import TopicElement from '~/components/TopicElement.vue'
export default {
middleware: ['check-auth', 'auth'],
computed: {clients() {return this.$store.getters.getClients}},
methods(){
showClient(){
console.log("click");
// this.currentClient = client;
}
},
</script>
我收到此错误:
属性或方法“ showClient”未在实例上定义,但在渲染期间被引用。通过初始化属性,确保在data选项中或对于基于类的组件,此属性都是反应性的。参见:https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties。
有人可以帮助我并解释我为什么得到它吗?
答案 0 :(得分:1)
</template>
<script>
import NavigationElement from '~/components/NavigationElement.vue'
import TopicElement from '~/components/TopicElement.vue'
export default {
middleware: ['check-auth', 'auth'],
computed: {clients() {return this.$store.getters.getClients}},
methods:{
showClient(){
console.log("click");
// this.currentClient = client;
}
},
</script>
方法必须是对象而不是函数。