父传子
// 在子组件中声明
// props:['name1', 'name2' ....], 数组和对象props
//用于接收传的值
props: {
msg:{
type:String,
default:'############'
},
MyTitle: {
type:String,
required:true
},
article: {
type:Array,
default:['aaaa', 'bbbb', 'cccc'],
}
},
在父组件中传值
<my-main
msg="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;
},
},