vue学习9-更新视图
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<script src='https://unpkg.com/vue/dist/vue.js'></script>
<title></title>
</head>
<body>
<div id='app'>
<div>
<ul>
<li v-for="hear in hears">
{{hear}}
</li>
</ul>
<button @click="updata">更新</button>
<button @click="spliceHears0">操作添加</button>
<button @click="spliceHears1">操作替换</button>
<button @click="spliceHears2">操作删除</button>
</div>
</div>
<script>
new Vue({
el:'#app',
data:{
hears:['1','2','3']
},
methods:{
updata(){
this.hears=['更新后']
},
spliceHears0(){
this.hears.splice(0,0,"添加")
},
spliceHears1(){
this.hears.splice(0,1,"替换")
},
spliceHears2(){
this.hears.splice(1,1)
}
}
}
)
</script>
</body>
</html>

浙公网安备 33010602011771号