VUE 项目中 退出登入后 禁止返回键操作

HTML代码: (点击 退出登录时 触发 loginout命令,它在js中进行了监听

<el-dropdown class="user-name" trigger="click" @command="handleCommand">
                    <span class="el-dropdown-link">
                        {
   
   {username}} <i class="el-icon-caret-bottom"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item><p @click="changePassword">密码修改</p> </el-dropdown-item>
                        <el-dropdown-item divided  command="loginout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>

JS代码:

        // 用户名下拉菜单选择事件
        handleCommand(command) {
            if(command == 'loginout'){
                sessionStorage.clear();
                this.$router.push("/login");
                history.pushState(null, null, document.URL);
                window.addEventListener("popstate",function(e) {  
                    history.pushState(null, null, document.URL);
                }, false);
            }
        },

备注:

触发后禁止浏览器的后退键

              history.pushState(null, null, document.URL);

                window.addEventListener("popstate",function(e) {  

                    history.pushState(null, null, document.URL);

                }, false);

猜你喜欢

转载自blog.csdn.net/qq_42715494/article/details/103468000