英文:
Why the stores pinia is not defined?
问题
I'm expecting to return the store but I'm having an error useUsersStore is not defined. Even though the pinia store is correctly stored and exported to the component.
// Component
export default {
setup() {
const usersStore = useUsersStore();
const countries = usersStore.getCountries;
const scores = usersStore.getScores;
const country = ref('');
const score = ref('');
// etc.
}
}
// main.js
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';
const pinia = createPinia();
const app = createApp(App);
app.use(pinia);
app.mount('#app');
英文:
I'm expecting to return the store but I'm havin an error useUsersStore is not defined. Even though the pi nia store is corresctly stores and exported to th ecomponent.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
import { defineStore } from 'pinia';
export const useUsersStore = defineStore('usersStore', {
state: () => ({
...
}}
// Component
export default {
setup() {
const usersStore = useUsersStore();
const countries = usersStore.getCountries;
const scores = usersStore.getScores;
const country = ref('');
const score = ref('');
etc.
}}
// main.js
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';
const pinia = createPinia();
const app = createApp(App);
app.use(pinia);
app.mount('#app');
<!-- end snippet -->
答案1
得分: 1
“我遇到了一个错误,useUsersStore未定义”,当然你会遇到这个错误,因为你还没有导入它。
#### `Filters.vue`
```javascript
<script>
import { ref } from 'vue';
// 添加这个导入语句
import { useUsersStore } from '../stores/usersStore';
export default {
...
英文:
"I'm havin an error useUsersStore is not defined", Of course you will get the error, as you haven't imported it.
Filters.vue
<script>
import { ref } from 'vue';
// Add this import statement
import { useUsersStore } from '../stores/usersStore';
export default {
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论