【踩坑】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