当前位置:网站首页>H5 van-popup全屏弹窗,模拟页面回退效果,支持左上角返回按钮,适用物理返回,侧滑与底部返回键
H5 van-popup全屏弹窗,模拟页面回退效果,支持左上角返回按钮,适用物理返回,侧滑与底部返回键
2022-06-10 19:29:00 【小半Annie】
第一步:
1、定义animateDuration变量
2、定义open事件执行方法selectProjectOpenHandler
3、定义close事件执行方法selectProjectCloseHandler
data () {
return {
animateDuration: 0.3 // 默认弹窗动画时间0.3s
}
},
第二步:van-popup使用:
<!-- van-popup -->
<van-popup
v-model="_show"
position="right"
:overlay="false"
:style="{ width: '100%', height: '100%' }"
:duration="animateDuration"
@open="selectProjectOpenHandler"
@close="selectProjectCloseHandler">
<!-- 弹窗内容 -->
</van-popup>
第三步:
selectProjectOpenHandler:
// popup打开
selectProjectOpenHandler () {
window.history.pushState(null, null, '#') // 模拟新的一页history记录
window.addEventListener('popstate', this.popstateHandler) //添加popstate事件监听
}
popstateHandler (e) {
this.animateDuration = 0 // 防止侧滑出现多次动画
this._show = false //关闭van-popup
}
selectProjectCloseHandler:
// popup关闭
selectProjectCloseHandler () {
window.removeEventListener('popstate', this.popstateHandler, false)
},
第四步:按钮返回的方法goBack (重要!)
goBack () {
window.history.back() // 删掉van-popup打开时添加的history
this._show = false
},
效果杠杠的!!!具体的业务需求可以自行调整哈
边栏推荐
猜你喜欢

FS2117升压IC输出5V2.4A同步整流

观点丨Play and Earn 会让加密游戏误入歧途

SBC芯片35584数据手册预调节器翻译

Zabbix_ Monitoring ssh/crond Service - wechat alarm
![[enter textbook latex record]](/img/f0/5ca60f0894d4ae544e7399d18a3a42.png)
[enter textbook latex record]

One question to explain the past and present life of dynamic planning

KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器

一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息

Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003

Spark ShuffleManager
随机推荐
Which school do you choose after the college entrance examination? VR panoramic campus all-round display
Rotated sorted array
Esp8266 system environment setup
FS4521恒压线性充电IC
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
【录入课本latex记录】
Hm3416h buck IC chip pwm/pfm controls DC-DC buck converter
Fs2117 boost IC output 5v2.4a synchronous rectification
localhost和127.0.0.1的区别?
割舍绳子/整数分割
利用阿里云国际购买的服务器搭建个人网站步骤
Mobile power supply scheme for outdoor solar camping lamp
零信任架构
The old programmer said: stop translating the world, developers should return to programming
When can Flink support the SQL client mode? When can I specify the applicati for submitting tasks to yarn
uni-app自定义导航
It took 2 years, 442 authors and 132 institutions! Google released the new benchmark big bench for language model evaluation. 204 tasks comprehensively evaluated the language model ability, with paper
历时2年442位作者132个机构!Google发布语言模型评价新基准BIG-bench,204个任务全面评价语言模型能力,附论文
京东发布基于张量网络加速的大规模、分布式量子机器学习平台TeD-Q
KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器