vue.js - Child-Parent-Communication:找不到方法?
问题描述
我正在尝试使用 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”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保该属性是反应性的,无论是在数据选项中,还是对于基于类的组件。请参阅:https ://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties 。
有人可以帮助我并解释为什么我得到它吗?
解决方案
</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>
方法必须是对象而不是函数。
推荐阅读
- python - 将不同长度的样本附加到 numpy 数组
- coq - Successor 的计算行为
- python - Android Studio Chaquopy 吐司消息
- javascript - 是否有任何选项可以在 echarts 中指定 bin 的起始值和结束值
- jmeter - Apache Jmeter HTTP 标头管理器覆盖“主机”标头而不附加端口
- .net-core - 在.net core 3.1 中httptrigger 功能的应用洞察中添加Telemetry 日志
- android - 尝试连接 WIFI 时 Android Studio 模拟器“获取 IP 地址”
- python - 如何将值与两个矩阵组合并添加组合?
- sdk - 我的颤振项目有问题,涉及 SDK 版本,并且当我更新和保存 pubspec.yaml 时它失败了
- apache-httpclient-4.x - HttpClient5 - 更改/删除了很多 API