I am working on managing cookies in the browser and utilizing an external plugin called vue-cookies. However, when I try to call its method in a Vue file using this.$cookies.get(...), I encounter an error in the browser:
TypeError: Cannot set property '$cookies' of undefined
Below is my code implementation:
- Main.js
import App from './App.vue'
import router from './router'
import VueCookies from 'vue-cookies';
import { createApp } from 'vue'
const app = createApp(VueCookies)
app.use(VueCookies);
createApp(App).use(router).mount('#app')
beforeMount() {
var cookie = "";
cookie = this.$cookies.get("testname");
console.log(cookie);
}