今天在調試 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 的形式。
