vue中配置后端接口服务信息
最重要一点:配置完信息后,重新启动服务 npm run dev
需要在config下的index.js中 找到
module.exports = {
dev: {
}
}
以此接口为例:
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://100.1.1.1:10', //设置你调用的接口域名和端口号 别忘了加http
changeOrigin: true
}
},
}
然后在main.js中引入axios npm install axios -d
import axios from 'axios'
Vue.prototype.$http = axios.create({
timeout: 10 * 1000
})
然后在vue组件中这样使用:
this.$http.get('/static/data/xxxxx.json')
.then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})