贴一篇 写好的上下移动排序代码“`




Vue 测试实例 - 菜鸟教程(runoob.com)


ul li{
text-decoration: none;
height: 30px;
list-style:none
}
ul li span{
float: left;
margin-left: 30px;
width:100px;
text-align: center;
}
span:first-child
{
background:yellow;
}
span:nth-child(2)
{
background:red;
}
span:nth-child(3)
{
background:green;
}


  • {{items}} up down
new Vue({ el: '#app', data: { fruits : ['周杰伦', 4, 5, 'hello', 1, {ddd:111}] }, methods: { up: function (items) { this.fruits.forEach((it, index)=>{ if(items===it&&index!==0){ this.fruits.splice(index, 1); this.fruits.splice(index-1, 0, items); } }); }, down: function (items) { let index = this.fruits.indexOf(items); if(index !== (this.fruits.length - 1)){ this.fruits.splice(index, 1); this.fruits.splice(index +1, 0, items); } } } })


“`

相关文章: