I have installed the vue-cookies in my project.
I have included the following in the main.js file:
createApp(App)
.use(store)
.use(router, axios, VueCookies)
Then the script part in the App.vue file contains the following:
<script>
import Navbar from '@/components/layout/Navbar'
import axios from 'axios'
export default {
name: 'App',
components: {
Navbar
},
beforeCreate() {
console.log(this.$cookies)
This says cookies is undefined, so I can't set or get any cookies.
If I add a import VueCookies from 'vue-cookies' the result is the same.
Before, I used localStorage, and I used this beforeCreate to read the login information from it. I want to start using cookies to store the token between sessions, as I have read it's more secure.
I have searched arout a little bit I have not read anything regarding cookie initialization or anything else I have to do so that this.$cookies is not undefined.
I have never used this library. But looking at npm: https://www.npmjs.com/package/vue-cookies
You have to import the library and use the plugin.
import VueCookies from 'vue-cookies';
Vue.use(VueCookies)
***I assume that you have installed the library previously.