How to delete a piece of data in vue
Dec 21, 2022 am 10:41 AMHow to delete a piece of data in vue: 1. Delete a certain piece of data in the ordinary array through the "arr.splice(index, 1)" method; 2. Through "arr.findIndex(item => { ...}arr.splice(id1, 1)" method to delete a piece of data in the array object.
The operating environment of this tutorial: Windows 10 system, Vue version 3, Dell G3 computer.
How to delete a piece of data in vue?
vue deletes a certain piece of data in the array
Delete a piece of data in the array
Delete a normal array
let arr = [1,2,3,4,5]; //方法一 let index = arr.indexOf('3'); arr.splice(index, 1) //打印结果 [1,2,4,5] //方法二 let index = arr .findIndex(item => { if (item == '3') { return true } }) arr.splice(index, 1) //打印结果 [1,2,4,5]
Delete an array object
let arr = [ { id:1, name:'张三' }, { id:2, name:'李四' }, { id:3, name:'王二' }, { id:4, name:'麻子' }, ]; let id1 = arr.findIndex(item => { if (item.id == '3') { return true } }) arr.splice(id1, 1)
Use splice() to delete a piece of data in the array
1. When looping to output the array v-for="(item,index) in list" //Need to get the current subscript, item
2. Click the delete button to pass a parameter, in this pop-up window method Get this parameter in. Set a blank in data and assign the parameter to this value.
3. Click the delete button in the pop-up window to get this array.splice(obtained subscript value, 1);
Recommended learning: "vue.js video tutorial"
The above is the detailed content of How to delete a piece of data in vue. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI

AI startups collectively switched jobs to OpenAI, and the security team regrouped after Ilya left!

The difference between export and export default in vue
