vue-photo-preview
vue-photo-preview copied to clipboard
同时监听afterchange和close事件签名的事件失效
this.$preview.on('afterChange', res => { this.showSave = true }) this.$preview.on('close', res => { this.showSave = false this.$preview.self = null })
+1
附上个人解决方案
beforeRouteLeave(to, from, next) {
// 通过监听浏览器url尾部特征判断是否为close
if (/.*?&gid=.*?&pid=.*?$/.test(window.location.href)) {
this.$preview.self.close();
setTimeout(() => {
next(to.path);
});
} else {
next();
}
},
beforeRouteLeave并不能起作用
我也想说这个代码,vue-photo-preview这个打开图片的时候url后面是不会变的,只有PC端的那个滑动插件才会变,所以基于url判断是不可靠的
@xjy2016 那可能是需要options里面配置history为true,我也只是再我的项目里观察到url后面有变化(打开和切换),才想到监听beforeRouteLeave,切换路由时先关闭。
请问你最后有没有解决这个问题
@xiazhigithub 我这只是个思路(可以根据url尾部判断),上面的代码是路由跳转离开时才生效关闭的
好的 谢谢