axios 中文文档

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);
Logo

前往低代码交流专区

更多推荐