美文网首页
2018-06-14

2018-06-14

作者: cherylw | 来源:发表于2018-06-14 17:05 被阅读0次

vue项目中 props想返回一个对象的时候

es5的写法:

props:{

    testObj:{

        type:Object,

        default:function(){

            return {

                //要设置的数据

            }

        }

    }

}

es6(用箭头函数的时候注意返回的时候加个大括号)

//由于大括号被解释为代码块,所以如果箭头函数直接返回对象,必须在对象外面加上括号。

props:{

    testObj:{

        type:Object,

        default: () => ({

            //要设置的数据

        })

    }

}


相关文章

网友评论

      本文标题:2018-06-14

      本文链接:https://www.haomeiwen.com/subject/wvwyeftx.html