Vue function to discover if you are in a server or browser
npm i vue-fn-ssr --save
<template>
<div>
<ul>
<li>Browser {{isBrowser ? '👍' : '👎' }}<li>
<li>Server {{isServer ? '👍' : '👎' }}</li>
</ul>
<code>
{{ssr}}
</code>
</div>
</template>
<script>
import useSSR from 'vue-fn-ssr'
export default {
setup(props) {
const ssr = useSSR()
console.log('IS BROWSER: ', ssr.isBrowser ? '👍' : '👎')
console.log('IS SERVER: ', ssr.isServer ? '👍' : '👎')
return {
isBrowser: ssr.isBrowser,
isServer: ssr.isServer
ssr
}
}
}
</script>
- Server Side Rendering check
- TypeScript support
- Zero dependencies
const {
isBrowser,
isServer,
canUseWorkers,
canUseEventListeners,
canUseViewport,
} = useSSR()
🙏 Heavily inspired by use-ssr