'When i refresh page my api key remove value [closed]

I need not to remove the api Key when refreshing the page and this is my code



Solution 1:[1]

You just have to get your previously added cookies and dispatch them on mounted events. Add this lines:

computed: {
  apiKey() {
    return this.$store.getters['getApiKey'];·
  },
methods: {
  setApiKey(apiKey) {
    this.$store.dispatch('setApiKey', apiKey);
  },
  singIn() {
    loginUsers(this.email, this.password, this.setApiKey);·
    setTimeout(() => ·{
      this.$cookies.set('apiKey', this.apiKey, {
        path: '/',
        maxAge: 31536000,
      }),
    }, 1000);
  },
},
mounted() {
  let apiKey = this.$cookies.get('apiKey'); // Get previously set cookies
  this.$store.dispatch('setApiKey', apiKey); // Dispatch action
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeanpaul1304