码迷,mamicode.com
首页 > 移动开发 > 详细

vue通过axios请求本地json数据

时间:2018-10-12 01:27:46      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:port   --   fun   nbsp   请求   下载   function   vue   ati   

1.下载插件

   npm install axios --save

2.在main.js下引用axios

  import axios from ‘axios‘

  Vue.prototype.$http=axios

3.在static文件夹下写静态文件 home.json

{
"name":"xuexue",
"age":20
}

4.在组件中请求数据

this.$http.get(‘../../static/home.json‘)
.then(function(res){
console.log(res)
}
.catch(err=>{console.log(err)})
)

vue通过axios请求本地json数据

标签:port   --   fun   nbsp   请求   下载   function   vue   ati   

原文地址:https://www.cnblogs.com/zeng91/p/9775716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!