FEMessage / el-data-table

🥘Base on element-ui, makes crud easily
https://femessage.github.io/el-data-table/
MIT License
486 stars 112 forks source link

fix: 查询值为数组时的持久化问题 #300

Closed gd4Ark closed 4 years ago

gd4Ark commented 4 years ago

Why

当查询值为数组时,经过 queryUtil 后会将整个数组变成字符串,例如:

const value = [1,2,3,4]

const queryValue = value.toString().trim() // 1,2,3,4

const stringifyValue = encodeURIComponent(queryValue) // 1%2C2%2C3%2C4

const parseValue = decodeURIComponent(stringifyValue) // 1,2,3,4

How

在 encode 前先把值进行 JSON.stringify(),在 decode 后进行 JSON.parse(),同时把 JSON.stringify 放到 queryUtil 内部处理,则外部不再需要进行额外处理

const value = [1,2,3,4]

const stringifyValue = encodeURIComponent(JSON.stringify(queryValue)) // %5B1%2C2%2C3%2C4%5D

const parseValue = JSON.parse(decodeURIComponent(stringifyValue)) //  [1, 2, 3, 4]

Test

before

2020-05-08 14 21 07

after

2020-05-08 14 18 09

Docs

netlify[bot] commented 4 years ago

Deploy preview for el-data-table ready!

Built with commit 9da83cfe65cdcd38dbf7b012ab1b5485375cb72c

https://deploy-preview-300--el-data-table.netlify.app