javascript - 无法读取未定义的 nuxt / vuex 的属性
问题描述
过去几天我一直在学习 vuex,并且一直坚持让 getter 在我的页面上呈现。在fruits.js 文件内的商店文件夹中,我有一个简单的对象数组,并尝试使用getter 添加过滤器并将结果呈现在列表中。当我在 vue 开发工具中检查 vuex 时,它显示了具有正确结果的 getter 过滤器,但是当我尝试在页面上渲染时,我收到了这个错误:
无法读取未定义的属性(读取“getYellowFruit”)
<template>
<div class="getters-page">
<div class="container text-white">
<ul class="w-2/4 pt-10">
<li v-for="yellow in yellowFruit" :key="yellow">{{ fruit.name }}</li>
</ul>
</div>
</div>
</template>
<script>
export default {
data() {
return {}
},
computed: {
yellowFruit() {
return this.$store.getters.fruits.getYellowFruit
},
},
}
</script>
商店文件夹中的fruits.js:
export const state = () => ({
fruits: [
{ name: 'Apple', color: 'red' },
{ name: 'Orange', color: 'orange' },
{ name: 'Pineapple', color: 'yellow' },
{ name: 'Kiwi', color: 'green' },
{ name: 'Grapes', color: 'purple' },
{ name: 'Banana', color: 'yellow' },
],
})
export const mutations = {}
export const actions = {}
export const getters = {
getYellowFruit: (state) => {
return state.fruits.filter((fruit) => fruit.color === 'yellow')
},
}
解决方案
推荐阅读
- c# - 如何防止使用 alt + F4 关闭任何表单
- xamarin - 如何使用库 Plugin.MediaManager (Xamarin.Forms) 播放声音
- configuration - 如何正确地将第二个密码键盘添加到 ChipDNA 服务器配置文件?
- python - 使用boost python从c ++为python中的类成员变量赋值
- angularjs - 在 Heroku 上部署 MEAN 应用程序时出现 POST 404 错误
- apache - 达到由机器人流量 ERR_CONNECTION_TIMED_OUT 导致的 MaxRequestWorkers 限制
- api - Symfony4 API 控制器父级
- javascript - 在 MVC5 中提交时,带有表单的模态窗口不会关闭
- php - 在wordpress中自定义作者URL以显示用户信息
- sql - 计算 SQL Server 中多行之间的时间差