1. Problems
When using vuepress to build documents, the following problems occur:
2. Reasons
This is because the static files generated by vuepress build are rendered through the node server. Therefore, there is a problem when the API of the browser/DOM is not accessed in the beforemount
or mounted
hook in the component.
3. Solutions
For the components introduced in the markdown file (. MD), use the built-in < ClientOnly>
component package
for example:
<ClientOnly>
<NonSSRFriendlyComponent/>
</ClientOnly>
However, the above method can not solve the problem of accessing the browser API by introducing a third-party component library into the component. You can use the on-demand loading function of import provided by ES6. Used in the mounted hook of the component.
<script>
export default {
mounted () {
// The introduced module will be loaded only when the component is mounted
import('./lib-that-access-window-on-import').then(module => {
// use code
})
}
}
</script>
Read More:
- [Solved] Vuepress Package Error: document is not defined
- [Solved] vite package Error: globalThis is not defined
- How to Solve “Vue is not defined” Error
- [Solved] vite2+vue3 jsx Error: React is not defined
- Ant design vue table Error: h is not defined [How to Solve]
- [Solved] Vue item error: Regeneratorruntime is not defined
- [Solved] JQuery each Method Error: $XXX is not defined
- [Solved] Vue 3 Script Setup ESLint Error: ‘defineProps‘ is not defined
- [Solved] Uncaught ReferenceError: axios is not defined
- vue eslint error ‘process‘ is not defined no-undef [How to Solve]
- [Solved] Module build failed TypeError this.getOptions is not a function at Object.loader
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- [Solved] Vue3 process Error: Uncaught ReferenceError: process is not defined
- Javascript SecurityError: Failed to read the’localStorage’ property from’Window’: Access is denied for this document.
- [Go] Can structure/structure pointer be compared with operator == is not defined error
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- vue error: ‘ev’ is defined but never used (no-unused-vars)
- [Solved] Vue Error: error: ‘to‘ is defined but never used (no-unused-vars)
- [Solved] Vue Error: template or render function not defined
- [Solved] Vue Error: error ‘xxx‘ is defined but never used no-unused-vars