Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete array elements by vue.js

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "vue.js how to delete array elements", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "vue.js how to delete array elements" this article.

Vue.js method to delete array elements: 1, get the subscript of the elements that need to be deleted in the array; 2, calculate from the subscript, delete the element whose length is length.

The operating environment of this paper: windows10 system, vue.js 2.9, thinkpad T480 computer.

Do you remember that there is a method arr.splice (arr.indexOf (ele), length) that can help us delete any js array, which is very useful.

The arr.splice (arr.indexOf (ele), length) method means to first get the subscript of this element in the array, and then calculate from this subscript to delete the element of length length.

Code example:

Delete / / introduce jqueryexport default {data () {return {users: [{name:'zx', age:18 Addrress:' Nanjing, Jiangsu', email:'1773203101@qq.com', contacted:false,} {name:'zhiyi', age:19, addrress:' Beijing, China', email:'1773203101@qq.com' Contacted:false,}, {name:'zhuxu', age:20 Addrress:' Shanghai, China', email:'1773203101@qq.com', contacted:false,},]}} Methods: {deleteUser:function (user) {/ / means to get the subscript of this element first Then, starting with this subscript, delete the element this.users.splice (this.users.indexOf (user), 1) of length 1. The above is all the content of the article "how to delete array elements in vue.js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report