无法使用nuxtjs访问设备传感器。

问题描述 投票:0回答:1

我正试图在一个系统中收听陀螺仪事件。nuxtjs 应用。

我已经阅读了关于传感器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)我得到以下错误。

reference error

: 在开发模式下,当我试图启动 Gyroscope 对象安装前(即在)。createddata 钩子)。)

我也知道有一些其他的方法来访问传感器(例如 ondeviceorientation 事件),但我不知道它们有什么区别,哪种方式对我来说是最好的 nuxtvue所以,任何建议将被感激。

vue.js nuxt.js android-sensors gyroscope
1个回答
0
投票

我的问题是通过浏览 http 而不是 https.

© www.soinside.com 2019 - 2024. All rights reserved.