透過 100 多個技巧學習 Nuxt!

logrocket
nuxt-logrocket

適用於 Nuxt 的 LogRocket 模組,可協助您修正錯誤並了解使用者行為。

nuxt-logrocket

nuxt-logrocket

npm (scoped with tag)npmCircleCICodecovjs-standard-style

適用於 Nuxt.js 的 LogRocket 模組

📖 發行說明

功能

  • Nuxt 3 & Nuxt Bridge
  • 支援 Pinia 整合
  • 能夠在開發模式下執行

設定

  • 使用 yarn 或 npm 將 nuxt-logrocket 依賴項新增至您的專案
yarn add nuxt-logrocket

npm install nuxt-logrocket --save
  • nuxt-logrocket 新增至您 nuxt.config.ts 檔案的 modules 區段
import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
  modules: ['nuxt-logrocket'],

  logRocket: {
    id: '',
    dev: false,
    config: {
      //
    }
  }
})

選項

選項可以使用 執行階段配置nuxt.config.ts 中的 logRocket 區段傳遞。在大多數情況下,為必要的 id 選項設定值就足夠了。

以下是完整的選項列表

選項類型預設值必要
id字串''
dev布林值true
enablePinia布林值true
release字串null
consoleEnabled布林值true
networkEnabled布林值true
networkRequestSanitizer函式-
networkResponseSanitizer函式-
domEnabled布林值true
inputSanitizer布林值false
textSanitizer布林值false
baseHref字串null
shouldCaptureIP布林值true
rootHostname字串null
shouldDebugLog布林值true
mergeIframes布林值false

這是一個包含選項預設值的範例

{
  id: '',
  dev: true,
  enablePinia: true,
  config: {
    release: null,
    console: {
      isEnabled: true
    },
    network: {
      isEnabled: true,
      networkRequestSanitizer: () => {},
      networkResponseSanitizer: () => {}
    },
    dom: {
      isEnabled: true,
      inputSanitizer: false,
      textSanitizer: false,
      baseHref: null
    },
    shouldCaptureIP: true,
    rootHostname: null,
    shouldDebugLog: true,
    mergeIframes: false
  }
}

用法

當 LogRocket 正確設定後,會自動注入到您的應用程式中。預設情況下,此模組僅在 production 和用戶端事件上運作。

為了在您的應用程式中使用 LogRocket 的注入功能,您可以使用

const { $logRocket } = useNuxtApp()

請造訪 LogRocket 的網站以取得完整的功能列表:文件

Pinia

此模組會自動偵測 Pinia 儲存變異,並將其附加到 LogRocket 會議。

此功能預設為啟用,並且可以透過將 enablePinia 選項設定為 false 來停用。

import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
  modules: ['nuxt-logrocket'],

  logRocket: {
    id: '',
    enablePinia: false
  }
})

開發

  • 複製此儲存庫
  • 使用 yarn install 安裝依賴項
  • 使用 yarn run dev 啟動開發伺服器
  • 將您的瀏覽器指向 https://127.0.0.1:3000

授權許可

MIT 授權許可 - Alibaba Travels Co