vue3 动态传值给子组件
父组件:data() {return {msg: '',resType: '',interestAlias: '',}},methods: {onChange(event) {this.resType = event.target.valueconsole.log(this.msg)},getRes() {this.msg = [this.resType,
·
父组件:
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" />
子组件设置监听:
// 首先定义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
}
},
},
更多推荐
已为社区贡献1条内容
所有评论(0)