Experiencing difficulties with Vue.js + Pinia and need assistance to resolve these issues.
- Error: 'state:' is defined but never used.
Here is the snippet of code located in @/stores/user.ts
.
import { defineStore } from 'pinia'
export const useUserStore = defineStore('user', () => {
state: () => {
return {
name: ''
}
}
})
https://i.stack.imgur.com/NEOCw.png
- Error: Property 'name' does not exist on type 'Store<"user", {}, {}, {}>'
This file is part of the Vue files.
<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from '@/components/HelloWorld.vue'
import { useUserStore } from '@/stores/user';
const userStore = useUserStore()
</script>
<template>
<header>
< img alt="logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
<div class="wrapper">
<HelloWorld :msg="userStore.name" />
<nav>
<RouterLink to="/">Home</RouterLink>
</nav>
</div>
</header>
<RouterView />
</template>