在config文件夾中的index.js設(shè)置pxoxyTable
dev: {
// Paths
assetsSubDirectory: 'assets',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://localhost:8090/',//設(shè)置你調(diào)用的接口域名和端口號 別忘了加http
changeOrigin: true,
pathRewrite: {
'^/api': '' // 這里理解成用‘/api’代替target里面的地址檐什,后面組件中我們掉接口時(shí)直接用api代替 比如我要調(diào)用'http://localhost:8090/users'搜锰,直接寫‘/api/users’即可
}
}
},
......
在組建中結(jié)合vue-resource或者axios使用即可
methods: {
dataGet() {
this.$http
.get('/api/users', {
params: {},
headers: {
token: 'a'
}
})
.then(
res => {
console.info(res.data)
},
error => {
console.info(error)
}
)
},
......