目前正在玩 vue 和 vuex。我有一个可以从 localStorage 获取项目的状态。我无法弄清楚为什么在JSON.parselocalStorage 中的项目处于状态之后,不知何故一切都很好,除了_id它会是 null这就是我的状态和吸气剂的样子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> <sui-grid celled> {{ show_brochures }} </sui-grid></template><script>import { mapGetters } from 'vuex';export default { name: 'FillBrochure', computed: mapGetters(['show_brochures']),};</script>
添加回答
举报
0/150
提交
取消