[英]Pinia Store with Vue
我的組件出現錯誤。 有人可以幫助解決這個問題嗎? 我在 vue 3 版本中工作。 出現錯誤:“未捕獲(承諾)TypeError:無法讀取未定義的屬性(讀取'計數器')”有人有任何見解嗎?
這是我的代碼
松樹專賣店:
import { ref, computed } from "vue"
import { defineStore } from "pinia"
export const useCounterStore = defineStore("counter", {
state: () => {
return {
counter: 0
}
}
})
腳本:
<script setup>
import { computed, ref } from "@vue/reactivity"
import { useCounterStore } from "@/stores/counter"
const storeCounter = useCounterStore()
console.log(storeCounter)
console.log(storeCounter.store.counter)
console.log(storeCounter.counter)
</script>
和模板:
<template>
<div class="home">
<div class="count">{{storeCounter.counter}}</div>
</div>
</template>
這些 console.log 語句之一有效,另一個無效
console.log(storeCounter.store.counter); // bad syntax, no store object on storeCounter
console.log(storeCounter.counter); // correct
您所要做的就是刪除有問題的行。 簡單的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.