elementui cascader 取消選中 clearCheckedNodes

問(wèn)題現(xiàn)象

在列表的高級(jí)搜索form表單中使用el-cascader,點(diǎn)擊清空會(huì)清空所有搜索條件,但是el-cascader會(huì)顯示上一次選擇的值,想不讓節(jié)點(diǎn)高亮選中狀態(tài)。

文檔

查看文檔,有個(gè)clearCheckedNodes方法。

image
  1. 給cascader設(shè)置上ref,如下:
    ···
    <el-cascader v-model.trim ="cId" ref="cascader" :options="category" @change="handleChange"></el-cascader>
    ···

然后調(diào)用

    // 清空選中的節(jié)點(diǎn)
    this.$refs.cascader.$refs.panel.clearCheckedNodes(); 
    // 設(shè)置為空可以讓節(jié)點(diǎn)不高亮顯示
    this.$refs.cascader.$refs.panel.activePath = []; 

  1. 添加清空方法
if (this.$refs.cascader){
    this.$refs.cascader.$refs.panel.clearCheckedNodes()
    this.$refs.cascader.$refs.panel.activePath = []  
    this.$refs.cascader.$refs.panel.scrollIntoView()
    this.$refs.cascader.$refs.input.$refs.input.setAttribute('aria-expanded', false)
    this.$refs.cascader.$emit('visible-change', false)
    this.$refs.cascader.$refs.panel.$emit('visible-change', false)
    this.$refs.cascader.$refs.panel.$emit('close')
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容