微信内置浏览器h5监听手机返回键


vant:

mounted(){
        //手机后退键
        let self = this;
        if (window.history && window.history.pushState) {
            $(window).on('popstate', function () {
                self.goback();
            });
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function (event) {
                history.pushState(null, null, location.href);
            });
        }
    },

 

uniapp:

mounted() {
            var a = document.getElementsByClassName('uni-page-head-hd')[0];
            a.style.display = 'none';
            //手机后退键
            let self = this;
            if (window.history && window.history.pushState) {
                window.addEventListener('popstate', function (event) {
                    uni.redirectTo({
                        url:self.$pageUrl.trainDetails + `?PlanID=${self.PlanID}`
                    },300)
                });
            }
        },

 或者:

methods:{
            onBackPress(e){
              // console.log("监听返回按钮事件",e);
              uni.redirectTo({
                  url:self.$pageUrl.trainDetails + `?PlanID=${self.PlanID}`
              },300)
              // 此处一定姚要return为true,否则页面不会返回到指定路径
              return true;
            },
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM