【踩坑】vue 无法让后台保存 session

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

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

现在,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 的形式。

猜你喜欢

转载自www.cnblogs.com/lipohong/p/10728310.html