<el-dropdown
trigger="click"
szie="mini"
style="margin-left: 10px"
@command="handleCommand"
>
<span class="el-dropdown-link">
<img :src="userImg" class="user" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="a">退出</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
// 点击退出清除cookie中的token
handleCommand() {
// this.$message("click on item " + command);
this.clearCookie();
},
setCookie(access_token, exdays) {
undefined;
var exdate = new Date(); //获取时间
exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天数
//字符串拼接cookie
window.document.cookie =
"access_token" +
"=" +
access_token +
";path=/;expires=" +
exdate.toGMTString();
//expires是设置cookie的过期时间,toGMTString是将日期转为GMT的字符串进行拼接
},
clearCookie: function () {
undefined;
this.setCookie("", -1); //修改2值都为空,天数为负1天就好了
this.$router.push({ path: "/" });
},```
这里是清除access_token字段的
谁有清除全部cookie的方法 麻烦告知, 感恩的心❤ !