用elementUI搭建后台界面;不错的选择; 配合vue,这里不得不说跨域调试; 目前webpack是时下流行的打包工具。也叫前端自动化解决方案; 第一个坑就是:修改了js记得重新编译下; 之前遇到一个问题相同的http请求axios为什么获取不到data数据。一度怀疑是后端服务的问题。但是后端服务通过地址栏 可以直接访问到api;
知识点vue axios的代理配置
//index.js代码片段
proxyTable: {
'/api': {
target: 'https://www.dlite.cn/', //访问url
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': ''
}
}
},
//main.js代码片段
import axios from 'axios'
Vue.prototype.HOME = '/api'+'/weapp/getTell';//对应的请求地址
Vue.prototype.$axios = axios;//通过prototype
Vue.use(ElementUI, axios);
//xxx.vue文件中的代码片段请求方法,注意箭头函数
var urls = this.HOME;
this.$axios.get(urls).then((res)=> {
this.list=res.data;
console.log(res)
})
另外可以直接使用axios的另一个插件axios-jsonp
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有