我删除了`Cookies`的令牌和csrftoken,为什么还有它们?

时间:2018-03-15 07:23:51

标签: javascript cookies token

我有一个

这是我的关键代码:

        var that = this

        // clear sessionid, csrftoken
        that.$Cookies.remove('sessionid');
        that.$Cookies.remove('csrftoken');

        // login
        that.$http.post(Urls.users.login(), params).then((response) => {

          setTimeout(loading, 0)

          that.$Cookies.set('token', response.data.key);

          that.get_user_info()

        }).catch((response) => {
            debugger
            setTimeout(loading, 0)

          }
        )

main.js我这样配置,所以组件我可以使用this.$Cookies

import Cookies from 'js-cookie';
Object.defineProperty(Vue.prototype, "$Cookies", { value: Cookies })

您看到我删除了tokencsrftoken,但是当我访问登录API时,请求中仍然有tokencsrftoken

enter image description here

我是否清除了this.$Cookies中的令牌和csrftoken,它基本上没有明确成功。

1 个答案:

答案 0 :(得分:0)

我对这个问题很感兴趣。为什么我删除了一些cookie,但是当我发送请求时,cookie仍在标题中?

所以我发现你使用js-cookie,然后我转到github并获取此信息:

删除对当前页面路径有效的cookie:

Cookies.set('name', 'value', { path: '' });
Cookies.remove('name'); // fail!
Cookies.remove('name', { path: '' }); // removed!

重要!删除cookie时,您必须传递用于设置cookie的完全相同的路径和域属性,除非您依赖于默认属性。

希望可以帮助你〜

相关问题