props注意点

201 阅读1分钟

props注意点:对象的时候设置默认值不能直接()=>{},这样返回的是undefined,需要()=>{return {}}

props:{
    initData: {
        type: Object,
        default: ()=>{
            return {}
        }
    },
    filterList: {
        type: Array,
        //效果和data为什么是函数一样
        default: ()=>[]
    }
}

错误写法:

props:{
    initData: {
        type: Object,
        default: ()=>{}//返回是undefined
    }
}