目录结构
代码
index.html
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>18.2</title>
</head>
<body >
<div id="app">
<ul>
<li v-for="food in foodList">{{food}}</li>
</ul>
<ul>
<li v-for="food in foodList">名称:{{food.name}}价格:{{food.price}}</li>
</ul>
</div>
<script src="../lib/vue.js"></script>
<script src="js/main.js"></script>
</body>
</html>
main.js
var app=new Vue({
el:'#app',
data: {
foodList: [
{
name: "葱",
price: 10
},
{
name: "姜",
price: 5
}
]
}
});
效果