子组件通过$emit来向父组件传递数据(array)

2021-03-23  本文已影响0人  爱学习的新一

子组件

<button type="button" v-on:click="submit">确定</button>
//js
export default {
            props:["titleName","id","order"],
            methods: {
                submit:function(){
                this.$emit("ok",[this.titleName,this.id,this.order]) // 向父级传递["xiha",123,3]。        
                }
            }
    }

父组件

<index-popup v-on:ok="submit"></index-popup>
//js
export default {
        data() {
                return {
                titleName:"hahaha",
                id:132155,
                time:"1000",
                order:1,
                seen:false,
 
                }
            },        
            components: {
            'index-popup': IndexPopup
        },
            methods: {                
            submit:function(arr){
                console.log(arr)   
                this.titleName=arr[0];
                this.id=arr[1];       
                this.order=arr[2];   
            }
            }
    }
上一篇 下一篇

猜你喜欢

热点阅读