Vue 父组件传递给子组件,设置默认值为数组或者对象时

在vue 父子组件传参过程中,传递对象或者数组时,设置默认值为{}或者[]

错误写法:

 props: {
    pos: {
      type: [Object, Array],
      default: []//这是错误的!!!
    }
  },

正确的写法:

props: {
    pos: {
      type: [Object, Array],
      default: function(){
            return []
        }
    }
  }, 

 

posted @ 2022-07-28 09:52  黑白棋学弟  阅读(963)  评论(0编辑  收藏  举报