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

Vue click 事件绑定函数中播放音频的代码失效 #153

Closed
Dream4ever opened this issue Jun 18, 2021 · 0 comments
Closed

Vue click 事件绑定函数中播放音频的代码失效 #153

Dream4ever opened this issue Jun 18, 2021 · 0 comments
Labels
JS Javascript Vue Powerful framework

Comments

@Dream4ever
Copy link
Owner

解决过程

在用 Vue.js 开发 Web 页面的过程中,发现 click 事件绑定的函数中,有一行代码 document.querySelector('#answer-right').play() 在 iOS 下报错 DOMException

但是这行代码之前在 PC 和 Android 和 iOS 上都是没有问题的,可现在在 iOS 上就会报上面的错误。

因为这段代码是在 node.addEventListener('webkitAnimationEnd', someFunc)someFunc 函数里的,最开始以为是函数定义方式有问题,可检查代码发现函数就是用的最常规的定义方式 function someFunc() { ... },那就不是这里的问题。

后来又在想,是不是执行到这行代码的时候,对应的 DOM 节点还不存在,于是又把代码放到 this.$nextTick(() => { }) 的回调函数体中,发现还是有同样的问题。

最后实在没招了,继续观察代码,发现报错的这行代码是可以从 node.addEventListener('webkitAnimationEnd', someFunc)someFunc 函数里移出来的,并不会影响运行结果,于是尝试了一下,竟然解决问题了!

真是纳闷,虽然解决问题了,但还是不知道问题出在哪里,先记下来再说吧。

@Dream4ever Dream4ever added Vue Powerful framework JS Javascript labels Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS Javascript Vue Powerful framework
Projects
None yet
Development

No branches or pull requests

1 participant