vue.js删除列表中的一行
<div class="check-list"> <ul> <li v-for="(item,index) in goodsList"> <div cla
·
<div class="check-list">
<ul>
<li v-for="(item,index) in goodsList">
<div class="top fl" >
<img :src="item.isSelect ? 'images/check_box_unselected.png' : 'images/check_box_selected.png'" />
</div>
<div class="middle pic fl"></div>
<div class="fnally fr">
<p class="title">{{item.title}}</p>
<p class="money">¥{{item.money}}</p>
<p class="remove" @click="removeList(index)">{{index}}删除</p>
</div>
</li>
</ul>
<ul>
<li v-for="(item,index) in goodsList">
<div class="top fl" >
<img :src="item.isSelect ? 'images/check_box_unselected.png' : 'images/check_box_selected.png'" />
</div>
<div class="middle pic fl"></div>
<div class="fnally fr">
<p class="title">{{item.title}}</p>
<p class="money">¥{{item.money}}</p>
<p class="remove" @click="removeList(index)">{{index}}删除</p>
</div>
</li>
</ul>
</div>
methods: {
removeList : function(index){
var goodsList = this.goodsList;
goodsList.splice(index, 1);
alert('你删除了第'+index+'个');
}
}
通过for循环,获得列表的索引 index,然后把当前索引传到事件中,事件中通过形参,接受实参,然后删除当前索引的列表。
更多推荐
已为社区贡献11条内容
所有评论(0)