axios 的报错
解决方法:import axios from 'axios'// 在这里不能使用 Vue.use(axios)// Vue.use(axios)Vue.prototype.$http = axios而对于 vue-resource:import VueResource from 'vue-resource';Vue.use(VueResource);...
·
axios 在 webpack 打包报错:Uncaught (in promise) TypeError: Cannot read property ‘protocol’ of undefined
解决方法:
import axios from 'axios'
// 在这里不能使用 Vue.use(axios)
// Vue.use(axios)
Vue.prototype.$http = axios
模块引用:
// 基于vue的形式
var form = new FormData();
form.append('name', this.name);
form.append('phone', this.phone);
form.append('sex', this.sex);
form.append('photo', this.img);
form.append('user_address', this.address);
let config = {
headers: {'Content-Type': 'multipart/form-data'}
}; //添加请求头
this.$http.post('url', form, config)
.then(response => {
console.log(response.data);
})
// 或者是
this.$http({
method: 'post',
url: 'url',
data: form
})
而对于 vue-resource:
import VueResource from 'vue-resource';
Vue.use(VueResource);
更多推荐
已为社区贡献19条内容
所有评论(0)