Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

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

Open
allmors opened this issue Apr 10, 2024 · 0 comments

Comments

@allmors
Copy link

allmors commented Apr 10, 2024

environment

  • vue3: 3.2.22
  • pina: 2.0.14

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": "[email protected]",
        "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": "[email protected]",
        "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": "[email protected]",
        "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

image

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant