目前,我正在尝试使用nuxt 3和pinia建立一个用于国家管理的项目,但遇到了以下错误:
[h3] [unhandled] H3Error: defineStore is not defined
at createError (file:///home/johnr/Code/Personal/test/node_modules/h3/dist/index.mjs:191:15)
at Server.nodeHandler (file:///home/johnr/Code/Personal/test/node_modules/h3/dist/index.mjs:381:21) {
statusCode: 500,
fatal: false,
unhandled: true,
statusMessage: 'Internal Server Error'
}我用npx nuxi init初始化项目,然后运行npm,然后运行npm @pinia/nuxt。然后,我将pinia添加到nuxt.config.ts中:
// nuxt.config.js
export default {
// ... other options
modules: [
// ...
'@pinia/nuxt',
],
}并在存储/回in中创建了一个基本存储:
export const useCounterStore = defineStore('counter', () => {
const count = ref(0);
function increment() {
count.value++;
}
return { count, increment };
});并尝试在应用程序模板中使用返回的计数:
<template>
<div>
<p>The count is {{ counterStore.count.value }}</p>
</div>
</template>
<script setup>
import { useCounterStore } from './store/counter.js';
const counterStore = useCounterStore();
</script>发布于 2022-07-26 13:39:45
看起来您忘记在store/counter.js中导入store/counter.js了。
import { defineStore } from 'pinia'
https://stackoverflow.com/questions/73124132
复制相似问题