Home >Web Front-end >Vue.js >How to remove array values ​​in vue.js

How to remove array values ​​in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-10 10:21:282510browse

Method to remove array values ​​in vue.js: Use [arr.splice(arr.indexOf(ele),length)] to get the subscript of this element in the array and start from this subscript Calculates and deletes array values ​​of length length.

How to remove array values ​​in vue.js

The operating environment of this tutorial: windows10 system, vue2.5.2, this article is applicable to all brands of computers.

【Recommended related articles: vue.js

Method to remove array values ​​in vue.js:

Usage: arr.splice(arr.indexOf(ele),length): Indicates first getting the subscript of this element in this array, and then starting to calculate from this subscript, and deleting the length of length Elements

This deletion method applies to any js array

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

Related free learning recommendations: javascript (video)

The above is the detailed content of How to remove array values ​​in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more