vue、uniapp、js-删除代码

https://www.runoob.com/jsref/jsref-splice.html
splice() 方法用于添加或删除数组中的元素。

<template>
	<view>
		<!-- 删除 -->
		<!-- <view @click="delete(item.id,index)" :data-id="item.id">删除</view> -->
		<!-- <view @click="delete">删除</view> -->
		<!-- 如果涉及到多个,使用item.id -->
		<view v-for="(item, index) in artList" :key="index" style="padding: 1%;">
			<!-- 一张图 -->
			<view v-if="item.images!= undefined && item.images.length === 1" class="line1">
				<view>  <!-- @tap="article(item)" -->
					<view class="news-list">{{ item.title }}</view>
					<view class="grace-news-list-img-big">
						<image :src="item.images[0]"></image>
					</view>
					<view class="userTime">
						<text>{{item.tag}}</text> <text>{{ item.author }}</text> <text>{{ time }}</text>
					</view>
				</view>
				<view class="dislike" @click="dislike(item.id,index)" :data-id="item.id">
					<image src="../../static/android/delete.png"></image>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			
		},
		delete(e,t){
				var that = this;
				var artList = that.artList;
				var id = e;
				var index=t;
				uni.showModal({
					content: '不感兴趣?',
					success: function(res){
						if(res.confirm){
							// ,1
							artList.splice(index);
							that.artList=artList;
							uni.request({
								url:'http://api.hnwlcm.com:8081/articleCover/Recommend/'+id,
								method:'GET',
								success:res=>{
									uni.showToast({
										title:'删除成功',
										icon:'sucess'
									});
									artList.splice(index,1);
									that.artList=artList;
								},
								fail: () => {},
								complete: () => {}
								
							});
							
						}else if(res.cancel){
							console.log("取消")
						}
						
					}
				})//uni.showModal
			}// 删除
	}
</script>

<style>
	
</style>

猜你喜欢

转载自blog.csdn.net/qq_43239475/article/details/88051053