【问题标题】:Can't access device sensors using nuxtjs无法使用 nuxtjs 访问设备传感器
【发布时间】: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 对象时,我在开发模式中遇到了类似的错误(即在 createddata 挂钩中)。

我也知道还有一些其他方法可以访问传感器(例如 ondeviceorientation 事件),但我不确定有什么区别以及哪种方法最适合 nuxt/vue,所以任何建议都会不胜感激。

【问题讨论】:

    标签: vue.js nuxt.js android-sensors gyroscope


    【解决方案1】:

    我的问题是通过http而不是https浏览引起的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      相关资源
      最近更新 更多