<!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>