簡體   English   中英

我如何從 js async function 進入 Nuxt/Vue 商店

[英]How can i get in Nuxt/Vue Store from js async function

我在我的 Nuxt 項目中使用了指紋模塊,我是前端框架的新手。

我可以在控制台中獲取用戶指紋代碼,但我不能使用 VuexStore 實例。

if (process.browser) {
  const fpPromise = FingerprintJS.load();
  (async () => {
      // Get the visitor identifier when you need it.
      const fp = await fpPromise
      const result = await fp.get()

      // This is the visitor identifier:
      const visitorId = result.visitorId
      console.log(visitorId)
  })()
}

如何在 visitorId 的實例中使用 vuexStore?

您在哪里使用此代碼?

如果它在 Nuxt 插件中(例如/plugins/my-plugin.js ),那么你可以使用它

export default ({ store }) => {
  // your code
}

如此處所示: https://nuxtjs.org/docs/2.x/concepts/context-helpers


如果您在.vue文件中的常用script部分,那么這應該足夠了

if (this.$store.state.auth.loggedIn) {
  // your code
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM