html_and_vue/vue/12_列表渲染/2.key的原理.html

36 lines
858 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!--
p30待整理
-->
<div id="root">
<!-- 遍历数组 -->
<ul>
<li v-for="p in persons" :key="p.id">{{p.name}}-{{p.age}}</li>
</ul>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false
const vm = new Vue({
el:'#root',
data:{
persons:[
{id:'001',name:'张钧',age:33},
{id:'002',name:'温柔',age:23},
{id:'003',name:'桃梨',age:24},
{id:'004',name:'琪妙',age:35},
]
},
})
</script>
</html>