0
点赞
收藏
分享

微信扫一扫

vue2和vue3对props进行一个接收和校验,子组件对props进行接收,子组件更改props的值,子组件对props进行校验

zhyuzh3d 2022-01-05 阅读 73

1、可以是数组形式(数组形式比较宽松,很不严谨,不推荐)

props: ['goodsItem'],
data: function () {
  return {
    localGoods: this.goodsItem
  }
}
props: ['goodsItem'],
computed: {
  normalizedSize: function () {
    return this.goodsItem.trim().toLowerCase()
  }
}

2、可以是对象形式(强烈推荐,就应该使用这种方法),vue2中和vue3中使用方法没有什么不同

搭配es6的简略写法更香

props: {
  dataList: {
    type: Object,
    default: () => ({
    	a:1,
    	b:2
	})
  }
}

vue3demo:

export default {
  props: {
    listSubProject: {
      type: Array,
      default: () => [],
    },
    isPm: {
      type: Boolean,
      default: false,
    },
  },
  emits: ["evtEdit", "evtDetail", "evtDelete"],
  setup(props, { emit }) { }
举报

相关推荐

0 条评论