VUE返回上一层时对当前逻辑判断

2020-01-16 14:39:51

在移动端VUE项目中,默认有返回上一层的功能,例如安卓手机的左上角返回按钮。

当我们需要在返回上一级之前进行某些函数判断时,可以借助beforeRouteLeave 进行判断。

 具体作法:


beforeRouteLeave(to,from,next) {
 
       if (this.btnColorChange==false){
          MessageBox.confirm('',{
                   title:'确定要退出调查?退出将不保存答题记录',
                    cancelButtonText:'暂不',
                     confirmButtonText:'退出'
               })
               .then(action=>{
                   //退出
                  //  this.$router.push('/surveytest')
                  next()
               })
       }else {
         next()
       }
     		   
		    
     	},

这样就实现了在移动端退出当前页面返回上一级的时候进行了判断。其中的next()指向的就是判断执行后的上一级。



  • 2017-11-06 01:00:17

    撤销git add

    如何撤销git add,不小心执行了git add . 操作,但是又不能提交所有的文件,因为对应不同的分支,现在怎么样可以将git add 撤销回来

  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.