2017-05-24 41 views
0

我公司的一位前任開發人員寫了一個Vue.js typeahead組件,一切似乎都很好,直到我進入Internet Explorer 11爲止。當輸入一個有keyup函數綁定到它的輸入時有時不接受用戶輸入的字符。這似乎是我正在使用的代碼的性能問題。下面是導致問題的代碼,如果我將其全部刪除,並且不做任何輸入沒有問題。我可以提出哪些性能建議來加速它?Vue組件差的IE性能

searchResults: function(e){ 
     this.isShown = true 
     this.selectedIndex = 0 
     this.filterOptions() 

     if(this.wildcardSearch){ 
      var searchObj = {} 
      searchObj[this.displayProp] = 'Search For: <strong>'+this.search+'</strong>' 
      this.matches.unshift(searchObj) 
     } 
     // Show first 5 results 
     this.matches = this.matches.splice(0,5) 
    }, 
    filterOptions: function(){ 
     var lowSearch = this.search.toLowerCase() 
     var that = this 
     if (this.search) // don't filter on empty string 
      this.matches = this.options.map(function(o){ 
       if (o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1) 
        return o 
      }).filter(function(o){return o}) 
    }, 
+0

我沒有回答,但是您是否嘗試過更改事件以測試是否有助於使用「@ input」事件? –

回答

0
兩個 mapfilter使用

是多餘的,因爲特別是map被用作filterfilter是不是真的做任何事情。

這個什麼:

this.matches = this.options.filter(function(o) { 
    return o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1 
}) 

這麼說,我不明白爲什麼這會導致性能的影響,但它確實我看到的唯一問題(我寫這彷彿評論我可以)。