vue之axios請求數據本地json

1.下載插件

 npm install axios --save

2.下載vue-axios

npm install --save axios vue-axios

3.在main.js下引用axios

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
Vue.$http=axios //不加時 請求爲 this.axios.get()

4.在static文件夾下寫靜態文件 home.json

{
	"fuid": 1,
	"account":"12322343243",
	"phone": "13200000000",
	"displayName": "代收款",
	"companyName": "代收款科技公司",
	"accountType":[
		{"id":1,"name":"經銷商","value":1},
		{"id":2,"name":"客服","value":2}
		],
	"remark": "帳號的備註信息"
}

5.在組件中請求數據

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章