https://jsfiddle.net/Lucu3epf/
// assets/scripts/utils.js
export const u = navigator.userAgent
// pages/index.vue
<template>
<h1>Error: navigator is not defined</h1>
</template>
<script>
import { u } from '../assets/scripts/utils' // Error: navigator is not defined
export default {
created () {
if (process.client) {
console.log(u)
}
}
}
</script>
nuxt template: nuxt-community/starter-template
I think I need a solution that can use the JS library normally.
It should be pre-referenced, and for the first time it is the reason to render through the server.
Sorry, my English is not very good. I took advantage of Google Translate.
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This bug report is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c7049">#c7049</a>)</em></sub></div>