<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script><!--vue.min.js的库-->
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script><!--jQuery库-->
</head>
<body>
<div id="main">
<div v-for="item in rows">
<p>姓名:{{item.name}}</p>
<p>昵称:{{item.nick}}</p>
</div>
</div>
</body>
<script>
$(document).ready(function () {
$.getJSON("data.json", function (result, status) {
var v = new Vue({
el: '#main',
data: {
rows: result
}
})
});
});
</script>
</html>
test.json
[
{
"name": "王小婷",
"nick": "祈澈菇凉"
}, {
"name": "安安",
"nick": "坏兔子"
}, {
"name": "编程微刊",
"nick": "简书"
}
]
参考:ajax和axios请求本地json数据对比 https://www.jianshu.com/p/4b9cb79fedd5
原文作者:祈澈姑娘 关注「编程微刊」公众号 ,在微信后台回复「小程序」,获取小程序开发全套资料和500G编程资源教程。