<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<p id="box">
<ul>
<li v-for="item in arr">
<p>{{item.name}}</p>
<p>{{item.age.age2}}</p>
</li>
</ul>
</p>
</body>
</html>
<script type="text/javascript">
var vm = new Vue({
el:'#box',
data:{
arr:[{name:'张三',age:{age2:45},},
{name:'王五'}]
}
})
</script>
If part of the data provided by the background does not have the age attribute, an error will be reported through the v-for loop in the document
三叔2017-06-12 09:31:14
If it is displayed, it is fine if it is not displayed.
<li v-for="item in arr">
<p>{{item.name}}</p>
<p>{{item.age?item.age.age2:''}}</p>
</li>
过去多啦不再A梦2017-06-12 09:31:14
There may not be age2
{{item.age && item.age.age2 ? item.age.age2 :''}}