组件、v-model绑定,父组件子组件传值

<SG-Tree
    showIcon
    v-model="selectValue"
  >
  </SG-Tree>
props: {
  selectedKeys: {// 改model值是外界传入的
      type: Array,
      default: () => {
        return []
      }
    }
}
data () {
    return {
   // 不使用中间值的话。v-vodel改变,会触发属性改变,会报这个错:Avoid mutating a prop directly since the value will be overwritten 
      selectValue: this.selectedKeys, // 中间值,为了使不报错
   }
}

watch: {
  selectedKeys:{
      handler (val) {
        this.selectValue = val
      },
      deep: true,
      immediate: true
    }
}
原文地址:https://www.cnblogs.com/benbendu/p/13851689.html