Vue Js Detect Cookie is Enabled or Not: Vue.js can be used to check if a user’s browser has cookies enabled by using the navigator.cookieEnabled property. By accessing the navigator.cookieEnabled property, one can determine if cookies are enabled or disabled in the browser. In this tutorial, we will learn how to use native JavaScript properties and Vue.js to determine whether cookies are enabled or not.
How to check if cookies are enabled in Vue.js?
To check if cookies are enabled in Vue.js, you can use the native javascript inbuilt property called ‘navigator.cookieEnabled’ which helps to determine if cookies are enabled or not.Example below shows how to determine whether cookies are enabled or not.
Vue Js Check Cookie is On(Allow) or Off(Block)
<div id="app">
<p v-if="cookie">Cookie is enabled</p>
<p v-else>cookie is disabled</p>
</div>
<script type="module">
import { createApp } from "vue";
createApp({
data() {
return {
cookie: navigator.cookieEnabled
}
},
}).mount("#app");
</script>