需要使用父组件调用子组件的方法来实现动态传值。
父组件:
// 给子组件定义ref
<子组件 ref="child"></子组件>
export default {
methods:{
// 调用子组件方法,动态传参
invokeChildMethod(){
this.$refs.child.printAge(12)
}
}
}
子组件:
export default {
methods: {
printAge(age){
console.log(age); //12
}
}
}