第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

當(dāng)沒有結(jié)果時(shí),Vue 中的輸入字段失去焦點(diǎn)

當(dāng)沒有結(jié)果時(shí),Vue 中的輸入字段失去焦點(diǎn)

守候你守候我 2023-11-02 21:12:57
我有 Vue 應(yīng)用程序。在里面,我有一些輸入字段。如果該字段有任何結(jié)果,則前進(jìn)和后退按鈕可見,否則不可見。我的問題是,當(dāng)我在輸入字段中鍵入內(nèi)容時(shí),當(dāng)我鍵入沒有結(jié)果的內(nèi)容時(shí),輸入焦點(diǎn)松散。(見片段)急于解決這個(gè)問題嗎?new Vue({  el: '#app',  data: {    input: "",    items: [{        'id': 123,        'name': 'item1'      },      {        'id': 124,        'name': 'item2'      },      {        'id': 128,        'name': 'item3'      },      {        'id': 237,        'name': 'item4'      }    ]  },  computed: {    search_list_of_workorders: function() {      var self = this;      var search_string = this.input.toLowerCase();      // apply filter      var array = this.search_filter_array(this.items, search_string);      return array.slice(0, 10).map(a => a.id);    },    number_of_search_results: function() {      return this.search_list_of_workorders.length    },    display_results_buttons: function() {      return this.number_of_search_results > 0    },  },  methods: {    search_filter_array: function(array, search_string) {      return array.filter(function(el) {        var id_filter = el.id.toString().includes(search_string);        return id_filter;      });    },  }});<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script><div id="app">  <button type="button" v-if="display_results_buttons">        Back  </button>  <div v-if="display_results_buttons">({{ number_of_search_results }})</div>  <input placeholder="Search" type="text" list="searchDropDown" id="searchInput" name="selectEventInput" v-model="input" />  <datalist id="searchDropDown">     <option v-for="(item, index) in search_list_of_workorders" :value="item" :key="`optionEvents_${index}`" >     </option>  </datalist>  <button type="button" v-if="display_results_buttons">        Forward  </button></div>
查看完整描述

1 回答

?
胡說叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

使用v-show而不是v-if. 這將完美解決您的問題!

主要區(qū)別:

  • v-if:如果表達(dá)式通過,則僅將元素渲染到 DOM。

  • v-show:將所有元素渲染到 DOM,然后在表達(dá)式失敗時(shí)使用 CSS 顯示屬性隱藏元素。

用例:

  • v-show:昂貴的初始加載,便宜的切換,

  • v-if:初始加載成本低,切換成本高。

在您的情況下,切換是強(qiáng)制性的,并且可能需要多次,因此v-show是更好的解決方案。此外,它不需要重新渲染,也可以解決焦點(diǎn)丟失的問題。

new Vue({

  el: '#app',

  data: {

    input: "",

    items: [{

        'id': 123,

        'name': 'item1'

      },

      {

        'id': 124,

        'name': 'item2'

      },

      {

        'id': 128,

        'name': 'item3'

      },

      {

        'id': 237,

        'name': 'item4'

      }

    ]

  },


  computed: {


    search_list_of_workorders: function() {

      var self = this;

      var search_string = this.input.toLowerCase();


      // apply filter

      var array = this.search_filter_array(this.items, search_string);


      return array.slice(0, 10).map(a => a.id);

    },


    number_of_search_results: function() {

      return this.search_list_of_workorders.length

    },


    display_results_buttons: function() {

      return this.number_of_search_results > 0

    },

  },


  methods: {

    search_filter_array: function(array, search_string) {


      return array.filter(function(el) {

        var id_filter = el.id.toString().includes(search_string);

        return id_filter;

      });

    },

  }

});

<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script>

<div id="app">


  <button type="button" v-show="display_results_buttons">

        Back

  </button>

  <div v-show="display_results_buttons">({{ number_of_search_results }})</div>

  <input placeholder="Search" type="text" list="searchDropDown" id="searchInput" name="selectEventInput" v-model="input" />


  <datalist id="searchDropDown">

     <option v-for="(item, index) in search_list_of_workorders" :value="item" :key="`optionEvents_${index}`" >

     </option>

  </datalist>

  <button type="button" v-show="display_results_buttons">

        Forward

  </button>

</div>


查看完整回答
反對(duì) 回復(fù) 2023-11-02
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)