Nuxt3: 使用 nuxt-cookie-control (@dargmuesli/nuxt-cookie-control) 时出错

huangapple go评论71阅读模式
英文:

Nuxt3: Error using nuxt-cookie-control (@dargmuesli/nuxt-cookie-control)

问题

我想使用这个nuxt-cookie-consent包:

我正在使用Nuxt 3.3.1

这里还有一个示例,说明如何使用这个依赖项:https://stackblitz.com/github/dargmuesli/nuxt-cookie-control?file=playground%2Fapp.vue

根据README.md的说明,我已经安装了这个包并将我的nuxt.config.ts更改为以下内容:

// nuxt.config.ts
import vuetify from 'vite-plugin-vuetify'

export default defineNuxtConfig({
    ssr: true,
    css: [
        'vuetify/styles',
        '@mdi/font/css/materialdesignicons.min.css',
    ],
    vite: {
        // @ts-ignore
        // 目前这会导致类型错误,但希望很快就能修复 #justBetaThings
        ssr: {
            noExternal: ['vuetify'], // 添加 vuetify vite 插件
        },
    },
    build: {
        transpile: ['vuetify'],
    },
    modules: [
        async (options, nuxt) => {
            // @ts-ignore
            nuxt.hooks.hook('vite:extendConfig', config => config.plugins.push(
                vuetify()
            ))
        },
        ['nuxt-cookie-control', {
            //默认css (true)
            //如果将css设置为false,您仍然可以访问
            //您的颜色变量(例如,background-color: var(--cookie-control-barBackground))
            css: true,

            //启用或禁用css变量填充
            cssPolyfill: true,

            //如果您有子域(shop.yourdomain.com)
            domain: 'yourdomain.com',

            //如果要 tree-shake 区域设置要使用的区域
            locales: ['en', 'de'],

            //模态对话框打开器(cookie控制)
            controlButton: true,

            //阻止iframe,以防止它们添加其他cookie
            blockIframe: true,

            //cookie栏的位置:
            //'top-left', 'top-right', 'top-full',
            //'bottom-left', 'bottom-right', 'bottom-full'
            barPosition: 'bottom-full',

            dashInDescription: true,

            //默认颜色
            //如果要禁用颜色,请将颜色属性设置为false
            colors: {
              barTextColor: '#fff',
              modalOverlay: '#000',
              barBackground: '#000',
              barButtonColor: '#000',
              modalTextColor: '#000',
              modalBackground: '#fff',
              modalOverlayOpacity: 0.8,
              modalButtonColor: '#fff',
              modalUnsavedColor: '#fff',
              barButtonHoverColor: '#fff',
              barButtonBackground: '#fff',
              modalButtonHoverColor: '#fff',
              modalButtonBackground: '#000',
              controlButtonIconColor: '#000',
              controlButtonBackground: '#fff',
              barButtonHoverBackground: '#333',
              checkboxActiveBackground: '#000',
              checkboxInactiveBackground: '#000',
              modalButtonHoverBackground: '#333',
              checkboxDisabledBackground: '#ddd',
              controlButtonIconHoverColor: '#fff',
              controlButtonHoverBackground: '#000',
              checkboxActiveCircleBackground: '#fff',
              checkboxInactiveCircleBackground: '#fff',
              checkboxDisabledCircleBackground: '#fff',
            },

            //默认文本
            text: {
              barTitle: 'Cookies',
              barDescription: '我们使用自己的cookie和第三方cookie,以便我们可以向您展示这个网站,并更好地了解您如何使用它,以改进我们提供的服务。如果您继续浏览,我们认为您已经接受了这些cookie。',
              acceptAll: '全部接受',
              declineAll: '删除全部',
              manageCookies: '管理cookie',
              unsaved: '您有未保存的设置',
              close: '关闭',
              save: '保存',
              necessary: '必要的cookie',
              optional: '可选的cookie',
              functional: '功能性cookie',
              blockedIframe: '要查看此内容,请启用功能性cookie',
              here: '这里'
            }
        }]     
    ],
    head: {
        link: [
          { rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
          {
            rel: "stylesheet",
            href: "https://fonts.googleapis.com/css2?family=Lato&display=swap",
          },
        ],
    },
})

我还将我的app.vue更改为以下内容:

Nuxt3: 使用 nuxt-cookie-control (@dargmuesli/nuxt-cookie-control) 时出错

在启动应用程序时,它显示找不到模块 nuxt-cookie-control,但它在依赖项中列出了:

Nuxt3: 使用 nuxt-cookie-control (@dargmuesli/nuxt-cookie-control) 时出错

我做错了什么,为什么它找不到模块,即使它作为依赖项安装了呢?谢谢!

英文:

I want to use this nuxt-cookie-consent package:

I am using Nuxt 3.3.1

There is also a playground example on how to use the dependency here: https://stackblitz.com/github/dargmuesli/nuxt-cookie-control?file=playground%2Fapp.vue

As instructed in the README.md I have installed the package and changed my nuxt.config.ts to this:

// nuxt.config.ts
import vuetify from 'vite-plugin-vuetify'
export default defineNuxtConfig({
ssr: true,
css: [
'vuetify/styles',
'@mdi/font/css/materialdesignicons.min.css',
],
vite: {
// @ts-ignore
// curently this will lead to a type error, but hopefully will be fixed soon #justBetaThings
ssr: {
noExternal: ['vuetify'], // add the vuetify vite plugin
},
},
build: {
transpile: ['vuetify'],
},
modules: [
async (options, nuxt) => {
// @ts-ignore
nuxt.hooks.hook('vite:extendConfig', config => config.plugins.push(
vuetify()
))
},
['nuxt-cookie-control', {
//default css (true)
//if css is set to false, you will still be able to access
//your color variables (example. background-color: var(--cookie-control-barBackground))
css: true,
//enable or disable css variables polyfill
cssPolyfill: true,
//in case you have subdomains (shop.yourdomain.com)
domain: 'yourdomain.com',
//if you want to tree-shake locales set locales you want to use
locales: ['en', 'de'],
//modal opener (cookie control)
controlButton: true,
//block iframes to prevent them from adding additional cookies
blockIframe: true,
//position of cookie bar:
//'top-left', 'top-right', 'top-full',
//'bottom-left', 'bottom-right', 'bottom-full'
barPosition: 'bottom-full',
dashInDescription: true,
//default colors
//if you want to disable colors set colors property to false
colors: {
barTextColor: '#fff',
modalOverlay: '#000',
barBackground: '#000',
barButtonColor: '#000',
modalTextColor: '#000',
modalBackground: '#fff',
modalOverlayOpacity: 0.8,
modalButtonColor: '#fff',
modalUnsavedColor: '#fff',
barButtonHoverColor: '#fff',
barButtonBackground: '#fff',
modalButtonHoverColor: '#fff',
modalButtonBackground: '#000',
controlButtonIconColor: '#000',
controlButtonBackground: '#fff',
barButtonHoverBackground: '#333',
checkboxActiveBackground: '#000',
checkboxInactiveBackground: '#000',
modalButtonHoverBackground: '#333',
checkboxDisabledBackground: '#ddd',
controlButtonIconHoverColor: '#fff',
controlButtonHoverBackground: '#000',
checkboxActiveCircleBackground: '#fff',
checkboxInactiveCircleBackground: '#fff',
checkboxDisabledCircleBackground: '#fff',
},
//default texts
text: {
barTitle: 'Cookies',
barDescription: 'We use our own cookies and third-party cookies so that we can show you this website and better understand how you use it, with a view to improving the services we offer. If you continue browsing, we consider that you have accepted the cookies.',
acceptAll: 'Accept all',
declineAll: 'Delete all',
manageCookies: 'Manage cookies',
unsaved: 'You have unsaved settings',
close: 'Close',
save: 'Save',
necessary: 'Necessary cookies',
optional: 'Optional cookies',
functional: 'Functional cookies',
blockedIframe: 'To see this, please enable functional cookies',
here: 'here'
}
}]     
],
head: {
link: [
{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
{
rel: "stylesheet",
href: "https://fonts.googleapis.com/css2?family=Lato&display=swap",
},
],
},
})

I have also changed my app.vue to this:
Nuxt3: 使用 nuxt-cookie-control (@dargmuesli/nuxt-cookie-control) 时出错

When starting up my app, it says it can't find module nuxt-cookie-control, but it is listed in the dependencies:

Nuxt3: 使用 nuxt-cookie-control (@dargmuesli/nuxt-cookie-control) 时出错

What am I doing wrong, and how come it can't find the module even though it is installed as a dependency? Thanks!

答案1

得分: 1

检查播放场所;请确保使用完整的模块名称:

// `nuxt.config.ts`
export default defineNuxtConfig({
    modules: [
        '@dargmuesli/nuxt-cookie-control'
    ],

    cookieControl: {
        // 选项
    }
}
英文:

Check the playground; make sure to use the full module name:

// `nuxt.config.ts`
export default defineNuxtConfig({
    modules: [
        '@dargmuesli/nuxt-cookie-control'
    ],

    cookieControl: {
        // options
    }
}

huangapple
  • 本文由 发表于 2023年4月4日 16:53:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定