【发布时间】:2020-06-18 21:45:31
【问题描述】:
我目前正在通过 moveIndex 方法和使用键事件根据图像的索引更改图像类别。我可以在计算机中顺利完成此操作,但对于电视,这需要花费太多时间。每当我使用较小的阵列时,流程都会顺利完成,但在较大的阵列中,流程会花费太多时间。这是一个可以帮助您澄清问题的代码块:
<template>
<div>
<h2>Kanal Listesi</h2>
<div class="container">
<div>
<div is="Channel" v-for="(channel,index) in channels" :key="index" :channel="channel"></div>
</div>
</div>
</div>
</template>
<script>
import channelz from "../trsubs.channels.json";
import Channel from './Channel';
export default {
components:{
Channel
},
data() {
return {
channels: Object.freeze(channelz.Root.Channels.Channel),
currentIndex: 1,
columnNumber: 9,
rowNumber: 7
};
},
moveIndex(e) {
var images = document.querySelectorAll("div > div > div > div > img");
images[this.currentIndex-1]["className"] = "";
switch (e.keyCode) {
case 37:
this.currentIndex =
this.currentIndex === 1
? this.channels.length - 1
: this.currentIndex - 1;
break;
case 38:
this.currentIndex =
this.currentIndex - this.columnNumber > 0
? (this.currentIndex -= this.columnNumber) : this.currentIndex
break;
case 39:
this.currentIndex =
this.currentIndex === this.channels.length - 1
? 1
: this.currentIndex + 1;
break;
case 40:
this.currentIndex =
this.currentIndex + this.columnNumber < this.channels.length
? (this.currentIndex += this.columnNumber)
: this.currentIndex;
break;
}
images[this.currentIndex-1]["className"] = "selectedIndex";
}
}
};
</script>
这是我的频道组件:
<template>
<div v-if="channel.ChName">
<img :src="'http://uyanik.tv/conf/images/'+channel.Image">
</div>
</template>
<script>
export default {
props:['channel']
}
</script>
【问题讨论】:
标签: javascript html arrays performance vue.js