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

来源:互联网 发布:算法复杂度分析 例题 编辑:程序博客网 时间:2024/06/07 19:00

最近遇到一个子组件传递多数据给父组件,最开始是当做字符串传多值,但没有成功,然后在网上找到这种方法,现在再这里记录下,给大家和自己参考下

子组件

<button type="button" v-on:click="submit">确定</button>//jsexport 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>//jsexport 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];               }            }    }
阅读全文
0 0