网站搜索
我有一个 <script setup> 块,在其中我导入了我的 testStore,但是每当我想在我的 Vue 文件中的某个地方使用 this.testStore.name 时,Vetur 就会给我这个错误:
Property 'testStore' does not exist on type 'CreateComponentPublicInstance<{ [x: string & 阅读更多 →
我正在像这样使用 Vue 3 的组合式 API:
store.ts
import { ref, Ref } from 'vue'; import { defineStore } from 'pinia'; export const useStore = defineStore('store', () => { const isLoading: Ref<boolean> = ref(true); function init() { isLoading.value = true; setTimeout(() => (isLoading.valu 阅读更多 →
我有一个 Nuxt3 项目,API 位于 server/api/<api-endpoints>。在某个端点中,当我尝试使用 Pinia Store 时,它显示:
或者当我尝试从 composables 访问一个可组合函数时,它无法定义任何变量(即使在组件中可以工作,也会显示 xxx 未定义,因此它无法在函数中定义任何东西)。
阅读更多 →
我在向 pinia store 添加 TypeScript 时遇到了一些问题,所以我想知道我该如何解决这个问题,这个项目使用的是 pinia:^2.0.16 和 Vue:3.2.37
这是错误:
类型 '{}' 缺少类型 'Order' 的以下属性:id、user_id、total、user、products
import type { ShoppingCart } from '@/Models/ShoppingCart' import type { Product } from '@/Mo 阅读更多 →
我正在使用 Vue 3 和 Pinia;我有一个用于向我的 API 发出请求的 API 服务,我已将其作为属性添加,以便在我所有的 store 中都可用,具体如下:
main.ts:
import { http } from "@/services/http"; const store = createPinia(); store.use(({ store }) => { store.http = http }) 阅读更多 →
我正在使用 Vue 3 和 Pinia,并且想在我的 Pinia 仓库中使用组合式 API。给定以下示例仓库
export const useMyStore = defineStore("my", () => { const currentState = ref(0); return { currentState }; } );我可以直接修改 currentState
阅读更多 →在这里开设这家店:
interface Task { id?: string; name: string; done: boolean; } interface TodoState { tasks: Task[]; loading: boolean; } export const useTodoStore = defineStore({ id: 'todo', state: (): TodoState => ({ tasks: [], loading: false, }), getters: {}, actions: { async addTask(name: string): Promise<void> { this.loading = true; this.tasks.push({ name, done: false, id: generateID() }); await sleep(200); this.loadi 阅读更多 →
我在以下代码中遇到了一个奇怪的错误: 属性 'length' 在类型 '{ [RefSymbol]: true; }' 上不存在。
但是当我在 getCount 函数中检查 foo 的类型时,我的 IDE 告诉我是 Foo[] 类型。我哪里做错了?
import { defineStore } from 'pinia'; import { useStorage } from '@vueuse/core'; interface Foo {} export const useFooSto 阅读更多 →
我正在实现一个认证存储(使用 Firebase),并且根据认证情况我想将用户路由到登录/已登录页面。
我基本上是想完成这个:https://github.com/dannyconnell/vue-composition-api-course/blob/module-23/vue-composition-api-noteballs/src/stores/storeAuth.js
但是在 TypeScript 中。
在我的 main.ts 中,我确实将 store 声明为属性:
const app = createApp(App); const pinia = cr 阅读更多 →
我有一家商店。
export const useGameStore = defineStore("game", { state: () => gameBaseState, getters: { foundMarkers(state): Marker[] { return state.markers.filter((m) => m.found); }, ... }, actions: { closeAll 阅读更多 →