公司要求做一个对话窗口,并要求对话内容存到数组里,那你看,这不就用上了
一、template部分:
<template>
<div>
<div style="width:20px;height:20px;background:red" v-for="(item,index) in arr.slice().reverse()" :key="index">{
{item}}</div>
</div>
</template>
二、script部分:
<script>
export default {
data(){
return {
arr:[1,2,4,5,6,7,8,9,10] //这个是原数组,可以看到页面已经是呈现倒叙展示了
}
}
}
</script>
总结:其实主要考察的还是js数组的slice()和reverse()的联合使用,当然也可以用其他方法,比如vue的监视属性等,希望对你有帮助!