码迷,mamicode.com
首页 > 编程语言 > 详细

js点击删除当前项,并把删除的哪行放到数组的第一个

时间:2019-05-20 17:23:18      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:一个   lis   src   数组   ext   body   https   pre   new   

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<ol>
<li v-for="(site,index) in sites" @click="changePosition(site,index)" style="border-bottom: 1px solid #999;">
{{ site.name }}
</li>
</ol>
</div>

<script>
new Vue({
el: ‘#app‘,
data: {
sites: [
{ name: ‘a‘ },
{ name: ‘b‘ },
{ name: ‘c‘ },
{ name: ‘d‘ },
{ name: ‘e‘ },
{ name: ‘f‘ },
{ name: ‘g‘ },
{ name: ‘h‘ },
{ name: ‘i‘ },
],

},
methods:{
//点击删除当前项,并把删除的哪行放到数组的第一个
changePosition(site,index){
var el = event.currentTarget;
console.log("当前文字:"+el.innerText);
console.log("当前索引:"+index)
//this.sites.unshift(this.sites.splice(this.listIndex,1).join());
this.sites.unshift(this.sites.splice(index,1)[0]);//删除的不是 数字就把.join() 改成 [0]
}
}
})
</script>
</body>
</html>

js点击删除当前项,并把删除的哪行放到数组的第一个

标签:一个   lis   src   数组   ext   body   https   pre   new   

原文地址:https://www.cnblogs.com/chengyalin/p/10894941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!