Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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": "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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant