当我刷新页面时,我的 api 键删除值

When i refresh page my api key remove value

刷新页面时我不需要删除 api 键,这是我的代码

您只需获取之前添加的 cookie 并在安装的事件上分派它们。添加此行:

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
}