vue之axios请求数据本地json
程序员文章站
2022-06-17 15:59:11
...
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)})
)
上一篇: vue中4个自定义指令讲解及实例用法
下一篇: 详解vue保存自动格式化换行