
父传子
// 在子组件中声明// props:['name1', 'name2' ....], 数组和对象props//用于接收传的值props: {msg:{type:String,default:'############'},MyTitle: {type:String,required:true},article: {type:Array,default:['aaaa', 'bbbb', 'cccc'],}},
在父组件中传值
<my-mainmsg="hello":MyTitle="msg":article="article"></my-main>
<button @click="changenum(2)">+2</button>methods: {changenum(num) {this.$emit('mycountevent', num);},},
<my-conn @mycountevent="mydemo"></my-conn>methods: {mydemo(data) {this.count += data;},},
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号