[英]Vue Component Poor IE Performance
在我的公司先前的开发者写了一Vue.js预输入组件,一切似乎与它的罚款,直到我到Internet Explorer 11,当输入到具有输入keyup
绑定到它有时不接受字符的用户功能正在输入。 我正在使用的代码似乎是性能问题。 下面是导致问题的代码,如果我将其全部删除并且什么也不做,则输入没有问题。 我有什么性能建议可以加快速度吗?
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})
},
使用的map
和filter
都是多余的,特别是因为map
被用作filter
并且filter
实际上并没有做任何事情。
那这个呢:
this.matches = this.options.filter(function(o) {
return o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1
})
就是说,我不明白为什么这会对性能产生影响,但这确实是我所看到的唯一问题(如果可以的话,我会写为注释)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.