Vue ssr introduces carousel plug-in to report error: window is not defined

vue ssr introduces carousel plug-in to report error: window is not defined;
the solution given in the official document is not quite clear: https://zh.nuxtjs.org/faq/win.

clipboard.png

1:


.vue

2:external_library


nuxt.config.js external_library

clipboard.png

clipboard.png

Aug.09,2021

if (process.BROWSER_BUILD) {
  require('external_library')
}

process.BROWSER_BUILD determine whether it is on the client
external_library refers to the module you want to apply

nuxt2

can be obtained globally via process.browser .
if (process.browser) {
  require('external_library')
}

and vendor: ['element-ui','external_library'] this has been removed from 2 without configuration.

Menu