Axios通信
Axios通信
vscode 安装liveserver插件 解决跨域
<!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>Title</title> <!--v-clock:解决闪烁问题--> <style> [v-cloak]{ display: none; } </style> </head> <body> <div id="vue" v-cloak> <div>{{info.name}}</div> <div>{{info.address.street}}</div> <a v-bind:href="info.url">点击</a> </div> <!--1.导入Vue.js--> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> <script> var vm = new Vue({ el: '#vue', //data vm的属性 //下面data()方法接收 data(){ return{ //请求的返回参数合适,必须和json字符串一样 info:{ name: null, address: { street: null, city: null, country: null }, url: null } } }, mounted(){//钩子函数 链式编程 ES6新特性 axios.get('data.json').then(response=>(this.info=response.data)); } }) </script> </body> </html>

浙公网安备 33010602011771号