組件、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
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM