我想访问父组件中的方法,并且该方法存在于子组件中。我试过用混合药。但是函数返回的是null而不是值。如果我试图发出对象,并且它在父组件中工作得很好。如何在vue3选项API中访问父类中的子方法?
Parent.vue
export default defineComponent({
name: 'App',
components: {
HelloWorld
},
mixins: [HelloWorld],
methods: {
fetchval(){
let x = this.getVal();
console.log(x);
}
}
});
</script>Child.vue
export default defineComponent({
name: 'HelloWorld',
dat(){
let val!: string;
return{
val,
}
},
computed: {
value: {
get() {
return this.val as string;
},
set(newval) {
val = newval;
}
}
},
methods: {
getVal(){
return this.value as string;
}
}
});
</script>https://stackoverflow.com/questions/72400204
复制相似问题