【问题标题】:Is it possible to add an attribute to a script loaded by nuxt是否可以向 nuxt 加载的脚本添加属性
【发布时间】:2022-11-10 18:36:06
【问题描述】:

是否可以向 nuxt 加载的脚本添加属性?

背景:我需要添加一个属性,以便 Cookiebot(https://www.cookiebot.com/en/) 确实忽略我的脚本。正确知道它阻止了一些,发送客户端请求。

【问题讨论】:

  • 在后台 vue 使用 webpack 生成文件,试试这个帖子中的答案stackoverflow.com/questions/51649065
  • 我找不到将属性添加到所有脚本块的方法。但是在我对所有 axios 请求使用代理模块之后,cookiebot 没有将它们发送到单独的后端域,而是停止阻止该脚本。
  • @David 我刚刚遇到了 nuxt 和 cookiebot 的类似问题。对我来说,页面坏了,因为一些 nuxt 脚本被 cookiebot 自动模式阻止了。将该脚本中的 cookie 重新分类(在我的情况下为“i18n_redirected”)作为基本 cookie 使页面再次运行,而无需对我的代码进行任何更改

标签: html vue.js webpack nuxt.js


【解决方案1】:

我知道这是一个迟到的答案,但我自己正在寻找这个。 Nuxt3 很简单。

在 nuxt.config.ts 中,将每个脚本标记及其属性定义为属性:

meta: {
  title: 'Page Title',
  meta: [
    { charset: 'utf-8' },
    { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  ],  
  {
    hid: 'cookiebot',
    id: 'Cookiebot',
    src: 'https://consent.cookiebot.com/uc.js',
    'data-cbid': 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx',
    'data-blockingmode': 'auto',
    type: 'text/javascript'
  }
}

在文档中阅读更多内容:https://v3.nuxtjs.org/getting-started/seo-meta/#meta-components

【讨论】:

    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 2022-01-05
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多