elementui select選項無法選擇的問題


<el-select
    v-model="confirmPriceVo.recUnit"
    filterable
    allow-create
    default-first-option
    @change='changeUnit'
    placeholder="單位(可選擇可自填)">
        <el-option
             v-for="(item, index) in ['字', '分鍾', '頁', '話']"
            :key="index"
            :label="item"
            :value="item"
            >
        </el-option>
</el-select>

出現這個問題就是綁定了對象(需求如此),render函數沒有自動更新,數據刷新了,但是視圖沒有刷新,而this.$set和this.$forceUpdate就是重新render。

解決辦法:

1.通過this.$set()解決

changeUnit(item) {
    // 向this.$set() 里傳入3個參數, 第一個是包裹字段的父級對象, 第二個是目標字段, 第三個是將要賦值給目標字段的數據
    this.$set(this.confirmPriceVo.recUnit,'recUnit',item);
}

2.通過this.$forceUpdate()解決

changeUnit() {
    this.$forceUpdate();
}

 


免責聲明!

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



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