- vue-resource的接口根域名全局配置
// 配置前
this.$http.get('http://localhost:3000/list').then(function (res) {
this.list = res.data;
})
// 全局配置
Vue.http.options.root = 'http://localhost:3000/';
// 配置后,调用的接口可以省略根域名http://localhost:3000/
this.$http.get('list').then(function (res) {
this.list = res.data;
})
- vue-resource的emulateJson全局配置
// 配置前
this.$http.post(url, data, { emulateJSON: true }).then(res => {
alert('添加成功!');
})
// 全局配置
Vue.http.options.emulateJSON = true;
// 配置后,就可省去post的参数 { emulateJSON: true }
this.$http.post(url, data).then(res => {
alert('添加成功!');
})
案例代码(Vue.http.options.html)运行浏览请参照here
$ git clone git@github.com:qmzgirl/vue-base-warehouse.git