axios的学习
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
xmlns:v-on="http://www.w3.org/1999/xhtml"
>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
[v-clock]{
display: none;
}
</style>
<body>
<div id="app" v-clock>
<div>{{info.name}}</div>
<div>{{info.address.country}}</div>
<a v-bind:href="info.url">点我</a>
</div>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
let vm = new Vue({
el: "#app",
data(){
return {
//请求的返回的参数格式 ,必须和JSON 字符串一样
info: {
name: null,
address: {
country: null,
},
url: null
}
}
},
mounted(){ //钩子函数
axios.get("demo02.json").then(response=>(this.info=response.data));
}
})
</script>
</body>
</html>
demo02.json
demo02.json 文件的内容 { "name": "李辉", "url": "https://www.cnblogs.com/lihui123/", "page": 1, "inNonProfit": true, "address": { "street": "含光门", "city": "陕西西安", "country": "中国" }, "links": [ { "name": "博客园", "url": "https://www.cnblogs.com/lihui123/" }, { "name": "李辉", "url": "https://www.cnblogs.com/lihui123/" }, { "name": "百度", "url": "https://www.cnblogs.com/lihui123/" } ] }