vue-resource 知识点

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;

posted on 2017-09-20 15:52  cag2050  阅读(144)  评论(0编辑  收藏  举报

导航