mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2025-12-29 04:20:22 +08:00
init
This commit is contained in:
30
src/composables/useAliveData.js
Normal file
30
src/composables/useAliveData.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**********************************
|
||||
* @Author: Ronnie Zhang
|
||||
* @LastEditor: Ronnie Zhang
|
||||
* @LastEditTime: 2023/12/05 21:22:28
|
||||
* @Email: zclzone@outlook.com
|
||||
* Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
|
||||
**********************************/
|
||||
|
||||
const lastDataMap = new Map()
|
||||
export const useAliveForm = (initData = {}, key) => {
|
||||
key = key ?? useRoute().name
|
||||
const lastData = lastDataMap.get(key)
|
||||
const aliveData = ref(lastData || { ...initData })
|
||||
|
||||
watch(
|
||||
aliveData,
|
||||
(v) => {
|
||||
lastDataMap.set(key, v)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
return {
|
||||
aliveData,
|
||||
reset() {
|
||||
aliveData.value = { ...initData }
|
||||
lastDataMap.delete(key)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user