Avoid using `process.server`, `process.client` and `process.browser` in client side hooksJS-E1000
It is recommended to avoid using process.server, process.client and process.browser in the following hooks :
- beforeMount
- mounted
- beforeUpdate
- updated
- activated
- deactivated
- beforeDestroy
- destroyed
The aforementioned hooks are available on the client-side.
The process.server, process.client and process.browser are available on the server-side, and accessing them in client side hooks might result in unexpected errors or even result as undefined.
Bad Practice
export default {
mounted() {
if (process.server) {
const city = 'NYC'
}
},
beforeMount() {
if (process.client) {
const city = 'NYC'
}
},
beforeDestroy() {
if (process.browser) {
const city = 'NYC'
}
}
}
Recommended
export default {
mounted() {
const city = 'NYC'
},
beforeMount() {
const city = 'NYC'
},
beforeDestroy() {
const city = 'NYC'
}
}