
用于 Nuxt.js 的 LogRocket 模块
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 | 字符串 | '' | 真 |
| 开发 | 布尔值 | 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 存储突变,并将其附加到 LogRocket 会话。
此功能默认启用,可以通过将 enablePinia 选项设置为 false 来禁用。
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: ['nuxt-logrocket'],
logRocket: {
id: '',
enablePinia: false
}
})
yarn install 安装依赖yarn run dev 启动开发服务器https://:3000MIT 许可证 - Alibaba Travels Co