用jsonp访问可解决跨域问题
(1)安装vue-resource npm install vue-resource -S
(2)在main.js中导入vue-resourse
import VueResource from ‘vue-resource‘
Vue.use(VueResource)
(3) 自定义上传方式,使用jsonp访问
uploadPdf(f) {
this.$http.jsonp(‘https://jsonplaceholder.typicode.com/posts/‘, {},
{
headers: {},
emulateJSON: true }).then((response) => {
console.log("success");
});
},
原文:https://www.cnblogs.com/xjenny/p/13496003.html