<!DOCTYPE html>
<html lang="en">
<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 type="text/javascript" src="js/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="root">
<button @click.once="chick">12322</button>
<ul>
<li v-for="(p,index) of persons" :key="index">
{{p.name}}-{{p.age}}
<input type="text">
</li>
</ul>
</div>
<script type="text/javascript">
new Vue({
el:'#root',
data:{
name:0,
persons:[
{id:'1',name:'张三',age:18},
{id:'2',name:'里斯',age:38},
{id:'3',name:'网速',age:18},
],
},
methods: {
chick(){
const p={id:'4',name:'王五',age:18}
this.persons.unshift(p)//加在前面,push是加在后面
}
},
})
</script>
</body>
</html>
vue简单案例
最新推荐文章于 2024-04-11 15:20:18 发布