【发布时间】:2020-04-28 12:41:17
【问题描述】:
我正在尝试在 nuxtjs 应用中监听 Gyroscope 事件。
我已阅读有关传感器 API 的信息,并尝试通过以下方式使用它:
mounted () {
this.gyroscope = new Gyroscope({ frequency: 60 })
this.gyroscope.addEventListener('reading', this.gyro_event)
this.gyroscope.start()
}
this.gyro_event 在哪里:
gyro_event (e) {
if (this.sensorData.time.length < 6000) {
this.sensorData.time.push(this.gyroscope.time)
this.sensorData.x.push(this.gyroscope.x)
this.sensorData.y.push(this.gyroscope.y)
this.sensorData.z.push(this.gyroscope.z)
}
}
当使用npm run dev 运行时,我没有收到任何错误。我也没有得到任何读数,但那是因为我的笔记本电脑没有陀螺仪。
在生产中运行时(提供npm run generate 的结果)我收到以下错误:
注意:在安装之前尝试初始化 Gyroscope 对象时,我在开发模式中遇到了类似的错误(即在 created 或 data 挂钩中)。
我也知道还有一些其他方法可以访问传感器(例如 ondeviceorientation 事件),但我不确定有什么区别以及哪种方法最适合 nuxt/vue,所以任何建议都会不胜感激。
【问题讨论】:
标签: vue.js nuxt.js android-sensors gyroscope