今天在调试 iblog 客户端时,发现登录后进行增加、删除、更新操作时都提示还没有登录。

此问题曾经在用 ajax 调试时出现过,解决办法是,在请求时带上 creditials: true ,即让发出请求时提交 cookies。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

现在,vue 也出现这个情况,怎么设置这个参数?方法很简单,针对使用 vue-resource 提交数据的设置如下:

        this.$http.post(url, {'数据': 数据值}, {'emulateJSON': true, 'credentials': true})
          .then((res) => {
              // do something
          })  
        this.$http.put(url, {'数据': 数据值}, {'emulateJSON': true, 'credentials': true})
          .then((res) => {
               // do something
          })    
this.$http.delete(url, {'credentials': true})
          .then((res) => {
              //do something
          })    

其中 'emulateJSON': true 是为了让提交的数据是 form data 的形式。

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄