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

xiaoxiao2021-02-28  8

“` 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); } } } })

“`

转载请注明原文地址: https://www.6miu.com/read-2150392.html

最新回复(0)