Skip to content

配置

nuxt.config.ts 中注册并配置模块。

typescript
export default defineNuxtConfig({
  modules: ['nuxt-web-plugin'],

  webPlugin: {
    // 网络请求全局配置
    network: {
      enabled: true,
      baseURL: 'https://api.example.com', // API 基础地址
      timeout: 10000, // 超时时间 (ms)
      retry: 1, // 失败重试次数
      withCredentials: true, // 跨域是否携带凭证
      headers: {
        'X-App-Version': '1.0.0' // 全局公共 Header
      }
    },
    
    // 安全功能配置
    security: {
      // 加密算法参数
      crypto: {
        symmetric: true,   // 启用对称加密
        asymmetric: true,  // 启用非对称加密
        hash: true,        // 启用哈希工具
        algorithm: 'AES-GCM',
        keySize: 256
      },
      // 加密存储配置
      encryption: {
        enabled: true,
        storage: true, // 启用 LocalStorage 加密
        cookies: true  // 启用 Cookie 加密
      }
    },

    // SEO 优化配置
    seo: {
      enabled: true,
      siteUrl: 'https://mysite.com', // 站点域名,用于生成绝对路径
      titleTemplate: '%s - 我的网站', // 标题模板
      defaultTitle: '我的网站',
      defaultDescription: '默认描述信息',
      defaultImage: '/share.jpg'
    }
  }
})

配置项说明

Network Options

属性类型默认值说明
enabledbooleantrue是否启用网络请求封装功能
baseURLstring''API 的基础 URL
timeoutnumber15000请求超时时间(毫秒)
retrynumber0请求失败后的自动重试次数
headersobject{}全局请求头

Security Options

属性类型默认值说明
crypto.algorithmstring'AES-GCM'对称加密使用的算法
encryption.storagebooleantrue是否注入 LocalStorage 加密 helper
encryption.cookiesbooleantrue是否注入 Cookie 加密 helper

SEO Options

属性类型默认值说明
enabledbooleantrue是否启用 SEO 助手
siteUrlstring''站点 URL,用于补全图片绝对路径
titleTemplatestring'%s'页面标题模板
defaultTitlestring''默认页面标题
defaultImagestring''默认分享图片地址

Released under the MIT License.