美文网首页
Vue的props里default: ()=> {}写法一个小坑

Vue的props里default: ()=> {}写法一个小坑

作者: FrankFang7 | 来源:发表于2023-08-06 15:16 被阅读0次

下面这种常见的这种写法是有问题的

 props: {
    myArray: {
      type: Array,
      default: ()=> []
    },
    myObject: {
      type: Object,
      default: ()=> {}
    },
},
created() {
    cosole.log("this.myObject",this.myObject)  // this.myObject undefined
  },

最简单的调整是加个括号

 props: {
    myArray: {
      type: Array,
      default: ()=> []
    },
    myObject: {
      type: Object,
      default: ()=> ({})
    },
}

相关文章

网友评论

      本文标题:Vue的props里default: ()=> {}写法一个小坑

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