【问题标题】:Do not allow exiting the form screen without saving不允许在未保存的情况下退出表单屏幕
【发布时间】:2019-01-12 01:28:24
【问题描述】:

当用户想要离开表单并填写输入而不保存时,我如何向用户发出警报?

我已经尝试在 beforeDestroy 内部实现一些东西,但我无法中止输出

我可以中止屏幕输出吗:

router.beforeEach((to, from, next) => {

  if(!store.getters.getStatusEdit){
    next(false);
  }

})

但是没有用,因为 beforeDestroy 里面运行的 vuex 跑在路由后面。

大家有什么建议吗?

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    内部组件使用:

    beforeRouteLeave (to, from, next) {
    
            if(this.dados.name){
    
                if(confirm('confirm?')){
    
                    next()
    
                }else{ next(false) };
    
            }else{
                next()
            }
        },
    

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      相关资源
      最近更新 更多