引入axios
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
Vue.config.productionTip = false
Vue.prototype.$axios = axios
vue.config.js
module.exports = {
devServer: {
open: true,
host: 'localhost',
port: 8080,
https: false,
hotOnly: false,
proxy: {
// 配置跨域
'/api': {
target: 'http://localhost:8080',
ws: true,
changOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
before: app => {}
}
};
json目录
axios请求
getData() {
this.$axios('api/data/profile/shopping.json')
.then( res => {
console.log(res.data)
})
}
错误提示