vue读取json可用代码

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="utf-8">
 5     <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
 6     <script src="./js/vue.min.js"></script>
 7     <script src="./js/axios.min.js"></script>
 8 </head>
 9 <body>
10 <div id="app">
11     {{ info }}
12 </div>
13 <script type = "text/javascript">
14     new Vue({
15         el: '#app',
16         data:{
17             info:null
18         },
19         mounted () {
20             axios
21                 .get('./data/json.json')
22                 .then(res => {
23                     this.info = res.data
24                 })
25                 .catch(function (error) { // 请求失败处理
26                     console.log(error);
27                 });
28         }
29     })
30 </script>
31 </body>
32 </html>

 

posted @ 2021-08-14 20:26  博二爷  阅读(191)  评论(0编辑  收藏  举报