vue通过axios请求本地json数据


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)})
)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM