網站搜尋

javascript - Typescript Vue 組件中的 Pinia store 出現錯誤「屬性 'testStore' 不存在於類型 'CreateComponentPublicInstance'……」

我有一個 <script setup> 區塊,在其中我導入了我的 testStore,但是每當我想在我的 Vue 文件中的某個地方使用 this.testStore.name 時,Vetur 就會給我這個錯誤:

Property 'testStore' does not exist on type 'CreateComponentPublicInstance<{ [x: string &am

閱讀更多 →

javascript - 如何同時模擬 Pinia 和 vue-i18n?

我正在這樣使用 Vue 3 的 Composition 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(() => (isLoad

閱讀更多 →

typescript - Pinia:無法從 Nuxt3 API 訪問 store

我有一個 Nuxt3 項目,裡面有一個位於 server/api/<api-endpoints> 的 Api。在某個端點裡,當我嘗試使用 Pinia Store 時,出現了如下錯誤:

或者當我嘗試從 composables 訪問一個可組合函數時,它無法定義任何變量(說 xxx 未定義,即使它在組件中可以運行,所以它在函數中根

閱讀更多 →

javascript - 如何使用 Typescript 在 pinia 中設置初始狀態

我在將 TypeScript 添加到 Pinia 儲存時遇到了一些問題,所以我想知道我該如何解決這個問題,這個專案使用的是 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 '@/Model

閱讀更多 →

vuejs3 - 我如何在 Typescript 中正確使用添加到我的 Pinia 儲存的自定義屬性?

我正在使用 Vue 3 搭配 Pinia;我有一個用來對我的 API 發送請求的 API 服務,我已經將它作為屬性添加,以便在我所有的 store 中可用,如下所示:

main.ts:

import { http } from "@/services/http"; const store = createPinia(); store.use(({ store }) => { store.http = http })

閱讀更多 →

javascript - 在使用 Composition API 時,通常如何在 Pinia store 中封裝數據?

我正在使用 Vue 3 和 Pinia,並且想在我的 Pinia 儲存中使用組合式 API。給定以下示例儲存

export const useMyStore = defineStore("my", () => { const currentState = ref(0); return { currentState }; } );

我可以直接修改 currentState

閱讀更多 →

typescript - 使用 Pinia 的 State 類型在 actions 中或外部被解構

有這家店在這裡:

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.loadin

閱讀更多 →

typescript - ts 的類型問題,useStorage(vueuse)和 Pinia

我在以下程式碼中遇到一個奇怪的錯誤: Property 'length' does not exist on type '{ [RefSymbol]: true; }'.

但是當我在 getCount 函數中檢查 foo 的類型時,我的 IDE 告訴我它的類型是 Foo[]。我哪裡做錯了?

import { defineStore } from 'pinia'; import { useStorage } from '@vueuse/core'; interface Foo {} e

閱讀更多 →

typescript - 如何在 pinia store 中使用 vue-router?

我正在實作一個認證商店(使用 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 =

閱讀更多 →

Pinia/TypeScript 從 action 訪問 getters — 屬性在類型上不存在

我有一家商店。

export const useGameStore = defineStore("game", { state: () => gameBaseState, getters: { foundMarkers(state): Marker[] { return state.markers.filter((m) => m.found); }, ... }, actions: { closeAll

閱讀更多 →