Seb-L / pinia-plugin-persist

Persist pinia state data in sessionStorage or other storages.
https://Seb-L.github.io/pinia-plugin-persist/
MIT License
214 stars 37 forks source link

When persisted into an array, the underlined fields will be changed to camel case. #71

Open allmors opened 4 months ago

allmors commented 4 months ago

environment

Problem statement When using pina persistence, if an array is stored and the field in the array object is underlined, the plug-in will change it to camel case.

  1. my code
    
    import { defineStore } from "pinia"

export const useItemStore = defineStore({ id: 'useItemStore', state: () => { return { rowItem: {

        }
    }
},
getters: {
    getCurItem(state) {
        return state.rowItem
    }
},
actions: {
    setMenuItem(val: any) {
        this.rowItem = val
    },
    resetData() {
        this.rowItem = {}
    }
},
persist: {
    enabled: true,
    strategies: [
        {
            key: 'useItemStore',
            storage: sessionStorage
        }
    ]
}

})

const data = [ { "id": "653773c022bd673a6b02dd88", "admin_id": "JSZH00005", "name": "root", "email": "1@qq.com", "phone": "13800000000", "role_id": "6537739b339a3a4728017968", "role_name": "amin", "status": 1, "node_id": null, "created_at": "2023-10-24 07:35:29", "updated_at": "2024-04-10 11:40:16" }, { "id": "64b89e21050ca676f20c191b", "admin_id": "JSZH00004", "name": "dev", "email": "1@qq.com", "phone": "15088888888", "role_id": "64b89defd7098d53b00a18f6", "role_name": "dev", "status": 1, "node_id": "123", "created_at": "2023-07-20 02:38:25", "updated_at": "2024-04-10 11:08:05" }, { "id": "64b0bac0e966e166d9093d23", "admin_id": "JSZH00001", "name": "admin", "email": "zdan@rightchaintech.com", "phone": "18688889999", "role_id": "64b0bac0e966e166d9093d22", "role_name": "superadmin", "status": 1, "node_id": "Ziz78vM5cAxBayywmAMnXFpLWe21UpeA5i", "created_at": "2023-07-14 03:02:24", "updated_at": "2024-04-10 11:53:19" } ] //use itemStore.setMenuItem(data)



2.The last underscored field in the array will not be changed to camelCase, and the other fields will be created with CamelCase.
![image](https://github.com/Seb-L/pinia-plugin-persist/assets/93471589/44f2974a-72a5-4762-8673-97dc566312ec)

![image](https://github.com/Seb-L/pinia-plugin-persist/assets/93471589/ed96f43e-c520-43ba-98b2-df1aa49ecd4d)

It can be seen that as long as it is not the last item in the array, underlined camel case data will be created.