Blogger Information
Blog 250
fans 3
comment 0
visits 321685
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue自学:数组中那些能做到响应式
梁凯达的博客
Original
705 people have browsed it

<!DOCTYPE html>

<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Vue自学:数组中那些能做到响应式</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="item in arr" :key="item">{{item}}</li>
</ul>
<button v-on:click="btClick">按钮</button>
</div>
</body>
<script type="text/javascript">
const app = new Vue({
el:’#app’,
data:{
arr:[‘a’,’b’,’c’,’d’,’e’],
},
methods:{
btClick(){
//直接索引修改:不会产生任何响应式效果
// return this.arr[0] = ‘aaa’
//push()方法:往数组最后插入一个元素
// return this.arr.push(‘aaa’);
//pop()方法:删除数组最后一个元素
// return this.arr.pop()
//shift()方法:删除数组第一个元素
//unshift():在数组最前面添加元素
// this.arr.unshift(‘添加元素:最前’)
// splice()方法:删除元素,插入元素,替换元素
//1、splice()方法删除元素
// this.arr.splice(1,4)
//2、splice()方法替换元素
// this.arr.splice(1,2,’abc’,’cbd’)
//3、splice()方法插入元素
// this.arr.splice(1,0,’abc’,’def’)

//重要:Vue.set(‘修改对象’,’索引值’,’修改什么值’)方法修改元素
Vue.set(this.arr,3,’cdf’)
}
}
})
</script>
</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post