欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決element-ui的el-select選擇器的@blur事件失效的坑

 更新時(shí)間:2022年09月13日 11:06:56   作者:F-Fanger  
這篇文章主要介紹了解決element-ui的el-select選擇器的@blur事件失效的坑,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

element-ui的el-select選擇器的@blur事件失效

element-UI文檔中本來el-select有個(gè)blur事件綁定函數(shù)屬性。

但是使用后發(fā)現(xiàn)有時(shí)候失焦事件并不能觸發(fā)生效,也就導(dǎo)致所綁定的函數(shù)不能執(zhí)行。

解決

利用el-select的@focus方法,在select標(biāo)簽內(nèi) 添加 ref 于此便可在focus事件內(nèi)觸發(fā) blur事件。

代碼如下:

 <el-select
            multiple
            filterable
            allow-create
            default-first-option
            v-model="request_msg"
            placeholder="請選擇或自行輸入拒絕原因"
            class="config-select"
            @focus="onBlur('request_msg', 'reqMsgRef')"
            ref="reqMsgRef"
          >
            <el-option
              v-for="item in refuseConfig"
              :key="item"
              :value="item"
              :label="item"
            ></el-option>
 </el-select>
onBlur(flag, ref) {
      this.$refs[ref].$refs.input.blur = () => {
      
      	// 這里執(zhí)行失焦的代碼
        const inp = this.$refs[ref].$refs.input.value
        if(!inp) return
        this[flag].push(inp)
      };
    },
  // this.$refs[ref].$refs.input 此根節(jié)點(diǎn)找到得根節(jié)點(diǎn)時(shí)輸入得input
  // this.$refs.select.$refs.reference.$refs.input 此根節(jié)點(diǎn)找到得是最外層得 input。包含被選中的數(shù)據(jù)在內(nèi)

使用el-select中的@blur遇到的問題

最近在使用elementui中的el-select的時(shí)候,想要達(dá)到的效果是失去焦點(diǎn)之后獲取el-select中選中的值,但是在實(shí)際使用中出現(xiàn)了如下問題:

1.直接使用@blur,第一次選中的時(shí)候,console的時(shí)候會(huì)輸出一個(gè)空的內(nèi)容,失去焦點(diǎn)再次輸出想要的內(nèi)容,

2.第二次選擇其他內(nèi)容會(huì)打印上一次選中的,失去焦點(diǎn)再次輸出想要的內(nèi)容

解決

1.使用*@blur.capture.native*

2.在methods中,對e.target.value進(jìn)行判斷,

? ?blurChange(e){
? ? ? if(e.target.value){ ?// 不加這句還會(huì)多輸出一次空白的
? ? ? ? console.log(e.target.value,'__________');
? ? ? }
? ? }?

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

最新評論