Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xjy2016 opened this issue Jun 13, 2019 · 8 comments
Open

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

xjy2016 opened this issue Jun 13, 2019 · 8 comments

Comments

@xjy2016
Copy link

xjy2016 commented Jun 13, 2019

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

@Y-qwq
Copy link

Y-qwq commented Jun 21, 2019

+1

@Y-qwq
Copy link

Y-qwq commented Jun 21, 2019

附上个人解决方案

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

@xiazhigithub
Copy link

beforeRouteLeave并不能起作用

@xjy2016
Copy link
Author

xjy2016 commented Jul 1, 2019

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

@Y-qwq
Copy link

Y-qwq commented Jul 1, 2019

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

@xiazhigithub
Copy link

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

@Y-qwq
Copy link

Y-qwq commented Jul 1, 2019

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

@xiazhigithub
Copy link

好的 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants