search

Home  >  Q&A  >  body text

javascript - vue 2.0 uses vue+webpack+vue-resource to build an environment. When running this.$http.post() locally, does it report an error?

In vue 2.0, in the environment built with vue webpack vue-resource, when running this.$http.post() locally... does it report an error?

天蓬老师天蓬老师2696 days ago1684

reply all(2)I'll reply

  • 某草草

    某草草2017-07-03 11:43:26

    You are reporting a cross-domain error. Please check if there is any problem with the interface first!

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-03 11:43:26

    It’s cross-domain, big brother.

    • Solution 1: Backend engineers are required to cooperate in setting Access-Control-Allow-Origin to *

    一定要设置 {emulateJSON: true},不然跨域不成功. 
    如果Web服务器无法处理编码为application/json的请求,你可以启用emulateJSON选项。启用该选项后,请求会以application/x-www-form-urlencoded作为MIME type,就像普通的HTML表单一样
    • Solution 2: this.$http.jsonp('...', { credentials: true }) Use JSONP

    Off topic: It is recommended to use axios vue-resource to officially stop maintenance in the future. It is almost the same in use

    reply
    0
  • Cancelreply