亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JSON.parse 之后的 localStorage 在 vue 狀態下給出 null _id

JSON.parse 之后的 localStorage 在 vue 狀態下給出 null _id

素胚勾勒不出你 2023-05-25 16:54:29
目前正在玩 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>
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

以 _ 或 $ 開頭的屬性不會在 Vue 實例上代理,因為它們可能與 Vue 的內部屬性和 API 方法沖突。


查看完整回答
反對 回復 2023-05-25
  • 1 回答
  • 0 關注
  • 222 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號