我是靠谱客的博主 老实保温杯,这篇文章主要介绍vue3 动态传值给子组件,现在分享给大家,希望可以做个参考。

父组件:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data() { return { msg: '', resType: '', interestAlias: '', } }, methods: { onChange(event) { this.resType = event.target.value console.log(this.msg) }, getRes() { this.msg = [this.resType, this.interestAlias] console.log(this.msg) }, // 调用子组件 <FlowScheduleResult :msg="msg" />

子组件设置监听:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 首先定义props props: { msg: { type: Array, required: true, }, }, // setup setup(props, context) { console.log('flow: ' + props.msg) }, // 监听数据变化 watch: { msg(newValue, oldValue) { console.log('sss:' + newValue) if (newValue) { this.parentData = newValue } }, },

最后

以上就是老实保温杯最近收集整理的关于vue3 动态传值给子组件的全部内容,更多相关vue3内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部