vue-resource 知识点

时间:2021-08-04 00:57:09
this.$http.post('xxx', params, {emulateJSON: false, headers: {'Content-Type': 'application/json;charset=utf-8'}})
  .then(response => {
    console.log(response)
  })
  .catch(error => {
    console.log(error)
  })
  • vue-resource 使用示例:
        this.$http
// 可以设置过期时间为100ms,来模拟超时
// .get(this.url, { timeout: 100 })
.get(this.url)
.then((response) => {
console.log(response)
this.status = response.status
this.statusText = response.statusText
})
// 网络错误、url地址错误、请求超时,能被catch捕获
.catch((error) => {
console.log(error)
this.status = error.status
this.statusText = error.statusText
})
  • If your web server can't handle requests encoded as application/json, you can enable the emulateJSON option. This will send the request as application/x-www-form-urlencoded MIME type, as if from an normal HTML form.
Vue.http.options.emulateJSON = true;