在NUXT中间件中识别用户设备的最佳方法是什么

发布于 2025-01-19 05:35:31 字数 398 浏览 4 评论 0原文

您好,

我将使用 nuxtjs 开发一个 Web 应用程序。由于某些原因,我需要在中间件中识别用户的设备。我知道如何在请求上下文中获取用户代理,但很难手动区分所有设备。我还找到了 Nuxt/Device 模块,但无法在中间件中处理它。 我在我的中间件文件中尝试此代码:

import device from '@nuxtjs/device'

export default (context) => {

  console.log(device)

}

buy 我只在控制台中获取模块详细信息。请分享您的经验来帮助我。

Greeting,

I'm going to develop a web application using nuxtjs. For some reasons I need to recognize users' devices in the middleware. I know how to get user agent in req context, but it is hard to distinguish all devices manually. I also found Nuxt/Device module but couldn't handle it in the middleware.
I try this code in my middleware file:

import device from '@nuxtjs/device'

export default (context) => {

  console.log(device)

}

buy I only get module details in my console. Please share your experience to help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿光 2025-01-26 05:35:31

对于中间件中使用NUXT/设备,我们必须在上下文中运行它。应用类似:

export default (context) => {

  console.log(context.app.$device)

}

for using Nuxt/Device in middleware we had to run it in the context.app like:

export default (context) => {

  console.log(context.app.$device)

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文