SDK integration error with Axeptio in Nuxt3
P粉396248578
P粉396248578 2024-03-27 14:17:30
0
1
412

I am currently developing a Nuxt3 project and need to integrate the scripts provided by Axeptio (cookie platform).

I made the Nuxt3 plugin to use their script integration

export default defineNuxtPlugin((useNuxtApp) => {
  ;(<any>window).axeptioSettings = {
    clientId: '...',
    cookiesVersion: '...',
  }

  ;(function (d, s) {
    var t:any = d.getElementsByTagName(s)[0],
      e: any = d.createElement(s)
    e.async = true
    e.src = '//static.axept.io/sdk.js'
    t.parentNode.insertBefore(e, t)
  })(document, 'script')
})

But this will throw

Uncaught TypeError: Cannot read attribute of undefined (read 'REACT_APP_SC_ATTR')

So I tried it in Nuxt2 and it worked fine.

What should I do to make it work?

P粉396248578
P粉396248578

reply all(1)
P粉578343994

Nuxt3 is based on Vite and therefore does not use process.env as Webpack4 does (in Nuxt2).
This is how to access environment variables in Nuxt3 by using import.meta.env.YOUR_COOL_ENV_VAR.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!