Vue2.0 axios 讀取本地json文件


參考:https://www.cnblogs.com/wdxue/p/8868982.html

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