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;
相關文章
相關標籤/搜索