You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>Key的原理</title> |
|
<script type="text/javascript" src="../vue.js"></script> |
|
</head> |
|
<body> |
|
<div id="root"> |
|
<!-- 遍历列表--> |
|
<h2>人员列表</h2> |
|
<button @click.once="addPerson">添加一个人</button> |
|
<ul> |
|
<!-- 方法一--> |
|
<!-- <li v-for="d in listData" :key="d.id">{{d.name}} - {{d.age}}</li>--> |
|
<!-- 方法二--> |
|
<li v-for="(data, index) in listData" :key="data.id"> |
|
{{data.name}} - {{data.age}} |
|
<input type="text"> |
|
</li> |
|
|
|
</ul> |
|
</div> |
|
</body> |
|
<script type="text/javascript"> |
|
Vue.config.productionTip = false |
|
const vm = new Vue({ |
|
el: "#root", |
|
data: { |
|
listData: [ |
|
{id: 1, name: '张三', age: 18}, |
|
{id: 2, name: '李四', age: 19}, |
|
{id: 3, name: '王五', age: 20} |
|
] |
|
}, |
|
methods:{ |
|
addPerson() { |
|
const p = {id: 0, name: "赵老大", age: 80} |
|
this.listData.unshift(p) |
|
} |
|
} |
|
}) |
|
|
|
</script> |
|
</html> |