如何在 Nuxt 中从一个组件调用方法或触发函数到另一个组件
·
我需要触发从一个组件到另一个组件的功能。不知道有没有必要。但无论这里是你的解决方案 -
假设有两个组件。其中一个我们可以称为A组件,另一个可以称为B组件-所以我将从B组件触发A组件功能。
在组件A-
created() {
this.$root.$refs.A = this;
},
// and here is the method which I called from `B` component
methods:{
print(){
// your others function logic
console.log('A component function called')
},
进入全屏模式 退出全屏模式
现在我通过一个函数从B组件中调用了这个print函数。
在组件B-
methods:{
printFromA(){
this.$root.$refs.A.print();
}
}
进入全屏模式 退出全屏模式
瞧!!!检查你的控制台😇
谢谢你。
更多推荐




所有评论(0)