【踩坑】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 的形式。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM