vue-photo-preview icon indicating copy to clipboard operation
vue-photo-preview copied to clipboard

同时监听afterchange和close事件签名的事件失效

Open xjy2016 opened this issue 6 years ago • 8 comments

this.$preview.on('afterChange', res => { this.showSave = true }) this.$preview.on('close', res => { this.showSave = false this.$preview.self = null })

xjy2016 avatar Jun 13 '19 03:06 xjy2016

+1

Y-qwq avatar Jun 21 '19 05:06 Y-qwq

附上个人解决方案

beforeRouteLeave(to, from, next) {
    // 通过监听浏览器url尾部特征判断是否为close
    if (/.*?&gid=.*?&pid=.*?$/.test(window.location.href)) {
      this.$preview.self.close();
      setTimeout(() => {
        next(to.path);
      });
    } else {
      next();
    }
  },

Y-qwq avatar Jun 21 '19 06:06 Y-qwq

beforeRouteLeave并不能起作用

xiazhigithub avatar Jul 01 '19 02:07 xiazhigithub

我也想说这个代码,vue-photo-preview这个打开图片的时候url后面是不会变的,只有PC端的那个滑动插件才会变,所以基于url判断是不可靠的

xjy2016 avatar Jul 01 '19 03:07 xjy2016

@xjy2016 那可能是需要options里面配置history为true,我也只是再我的项目里观察到url后面有变化(打开和切换),才想到监听beforeRouteLeave,切换路由时先关闭。

Y-qwq avatar Jul 01 '19 03:07 Y-qwq

请问你最后有没有解决这个问题

xiazhigithub avatar Jul 01 '19 03:07 xiazhigithub

@xiazhigithub 我这只是个思路(可以根据url尾部判断),上面的代码是路由跳转离开时才生效关闭的

Y-qwq avatar Jul 01 '19 03:07 Y-qwq

好的 谢谢

xiazhigithub avatar Jul 01 '19 03:07 xiazhigithub