vue(Js)从数组中删除元素

时间:2025-03-10 15:16:26

使用方法:((ele),length):表示先获取这个数组中这个元素的下标,然后从这个下标开始计算,删除长度为length的元素

这种删除方式适用于任何js数组

eg:

<template>
 <div class="users">
	<button type="button" class="btn btn-danger" v-on:click="deleteUser(user)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>删除</button>	
 </div>
</template>

<script>
//引入jquery

export default {

  data(){
		return {
			
			users:[
				{
					name:'zx',
					age:18,
					addrress:'江苏南京',
					email:'1773203101@',
					contacted:false,
				},
				{
					name:'zhiyi',
					age:19,
					addrress:'中国北京',
					email:'1773203101@',
					contacted:false,
				},
				{
					name:'zhuxu',
					age:20,
					addrress:'中国上海',
					email:'1773203101@',
					contacted:false,
				},
			]
		}
	},
	methods:{
		deleteUser:function(user){
			//表示先获取这个元素的下标,然后从这个下标开始计算,删除长度为1的元素
			((user),1);
		}
	}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--scope只会影响到当前组件的样式-->
<style scoped>
</style>