我们使用来自 https://github.com/yuche/vue-strap 的模态组件.单击浏览器后退按钮时,默认行为返回到先前的路径,但模式弹出窗口不会关闭。如何更改行为以在浏览器的后退按钮单击事件时关闭模态弹出窗口?
最佳答案
这对我有帮助。
https://jessarcher.com/blog/closing-modals-with-the-back-button-in-a-vue-spa/
created() {
const backButtonRouteGuard = this.$router.beforeEach((to, from, next) => {
if (from.name == 'menu') {
/* Blocking back button in menu route */
next(false);
this.yourCallBackMethod()
} else {
/* allowing all other routes*/
next(true);
}
});
this.$once('hook:destroyed', () => {
backButtonRouteGuard();
});
},
methods: {
yourCallBackMethod() {
// Go to the previous step, or close the modal
}
},
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
关于vue.js - 在vuejs中单击浏览器后退按钮时如何关闭模式弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44371895/