I integrated vue-cookies into my project successfully.
In the main.js file, I added the following code:
createApp(App)
.use(store)
.use(router, axios, VueCookies)
The script section in App.vue file looks like this:
<script>
import Navbar from '@/components/layout/Navbar'
import axios from 'axios'
export default {
name: 'App',
components: {
Navbar
},
beforeCreate() {
console.log(this.$cookies)
However, it seems that cookies are undefined, preventing me from setting or retrieving any cookie values.
Even after including
import VueCookies from 'vue-cookies'
, the issue persists.
Prior to this, I utilized localStorage to store login information and accessed it within the beforeCreate lifecycle hook. Now, I want to switch to using cookies for storing tokens across sessions due to enhanced security benefits.
Despite conducting some research, I could not find any information on initializing cookies or any additional steps needed to prevent this.$cookies
from being undefined.