html文件:
<!doctype html>
<html lang="en">
<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>Document</title>
</head>
<body>
<div id="app">
<ul>
<li>名称: {{info.name}}</li>
<li>年龄: {{info.age}}</li>
<li><a v-bind:href="info.url">{{info.url}}</a></li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data() {
return {
info: {
name: "",
age: ""
}
}
},
mounted() {
axios.get("data.json")
.then(response => this.info = response.data)
}
});
</script>
</body>
</html>
json文件——data.json
{
"name": "张三",
"age": "12",
"url": "https://www.baidu.com"
}