目前正在玩 vue 和 vuex。我有一個(gè)可以從 localStorage 獲取項(xiàng)目的狀態(tài)。我無(wú)法弄清楚為什么在JSON.parselocalStorage 中的項(xiàng)目處于狀態(tài)之后,不知何故一切都很好,除了_id它會(huì)是 null這就是我的狀態(tài)和吸氣劑的樣子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 }};中的樣品項(xiàng)目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>
JSON.parse 之后的 localStorage 在 vue 狀態(tài)下給出 null _id
素胚勾勒不出你
2023-05-25 16:54:29