如何解决vue-resource跨域问题vue-resource jsonp请求问题
在项目config目录下的index.js文件中的"dev"下,添加下面的代码,并改变使用的路径
proxyTable: {
'/api': {
target: 'http://localhost:80/',
changeOrigin: true,
pathRewrite: {
'/api': ''
}
}
},
target中写你想要请求数据的地址的域名
vue-resource jsonp请求问题
jsonp的用法
this.$http.jsonp('url',[可选参数,使用{}传参]).then(成功回调函数,失败回调函数);
<script type="application/javascript">
var vm = new Vue({
el:'#app'
,data:{
list:[]
}
,created(){
this.getData();
}
,methods:{
getData(){
var url = 'http://localhost:8080/abc';