Home > Article > Web Front-end > How to remove array values in vue.js
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.
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:'zx', age:18, addrress:'江苏南京', email:'1773203101@qq.com', contacted:false, }, { name:'zhiyi', age:19, addrress:'中国北京', email:'1773203101@qq.com', contacted:false, }, { name:'zhuxu', age:20, addrress:'中国上海', email:'1773203101@qq.com', 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!