您的位置:首页 > Web前端 > Vue.js

vue中配置后端接口服务信息

2018-07-03 15:03 253 查看

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)
})


阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐