当前正在使用vue和vuex。我有一个状态将从localStorage获取项目。我无法弄清楚为什么JSON.parse
在状态为localStorage的项目之后,除了_id
它为空之外,其他一切都很好
这就是我的状态和吸气剂的样子
const BROCHURES = 'brochures';
const state = {
brochures: JSON.parse(localStorage.getItem(BROCHURES)) || []
};
const getters = {
show_brochures: (state, getters, rootState) => {
console.log(state.brochures) // this will give me _id: null, but other fields are good
console.log(JSON.parse(localStorage.getItem(BROCHURES)) // this would return everything fine
}
};
样品中 getItem(BROCHURES)
[{ "has_feature_sheet": false, "images": [ "efsdf.png", "asdf.png" ], "instructions": [ { "sort": "1", "page": "1", "isImage": false, "textarea": "131111" } ], "isDeleted": false, "_id": "5f8e0765b041c24e230b36d2", "size": 2, "folds": 2, "price": 111, "createdAt": "2020-10-19T21:38:45.935Z", "updatedAt": "2020-10-19T21:38:45.935Z", "__v": 0 }]
在此先感谢您的帮助/建议。
编辑:这是我使用的地方 getters
<template lang="html">
<sui-grid celled>
{{ show_brochures }}
</sui-grid>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
name: 'FillBrochure',
computed: mapGetters(['show_brochures']),
};
</script>
以_或$开头的属性不会在Vue实例上被代理,因为它们可能与Vue的内部属性和API方法冲突。取自:https : //vuejs.org/v2/api/#data
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句