添加清楚state事件
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
VITE_APP_URL = http://192.168.31.82:8771
|
# VITE_APP_URL = http://192.168.31.82:8771
|
||||||
|
VITE_APP_URL = http://192.168.31.118:8771
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { showConfirmDialog } from 'vant'
|
import { showConfirmDialog } from 'vant'
|
||||||
|
import MyEvent from '@/utils/myEvent'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const currentRoute = computed(() => router.currentRoute.value.path)
|
const currentRoute = computed(() => router.currentRoute.value.path)
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
cancelButtonText: 'Cancel',
|
cancelButtonText: 'Cancel',
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
MyEvent.emit('clear-generate-state')
|
||||||
nav.path && router.push(nav.path)
|
nav.path && router.push(nav.path)
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
// 每一个存储的模块,命名规则use开头,store结尾
|
// 每一个存储的模块,命名规则use开头,store结尾
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import MyEvent from '@/utils/myEvent'
|
||||||
|
MyEvent.add('clear-generate-state', () => useGenerateStore().clearGenerateData())
|
||||||
|
|
||||||
export const useGenerateStore = defineStore({
|
export const useGenerateStore = defineStore({
|
||||||
id: 'generate', // 必须指明唯一的pinia仓库的id
|
id: 'generate', // 必须指明唯一的pinia仓库的id
|
||||||
state: () => {
|
state: () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { removeLocal, setLocal } from '@/utils/local'
|
import { removeLocal, setLocal } from '@/utils/local'
|
||||||
|
import MyEvent from '@/utils/myEvent'
|
||||||
export const useUserInfoStore = defineStore('userInfo', () => {
|
export const useUserInfoStore = defineStore('userInfo', () => {
|
||||||
const state = ref({
|
const state = ref({
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
@@ -48,6 +48,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
state.value.userInfo = {}
|
state.value.userInfo = {}
|
||||||
removeLocal('token')
|
removeLocal('token')
|
||||||
resetGenerateParams()
|
resetGenerateParams()
|
||||||
|
MyEvent.emit('clear-generate-state')
|
||||||
resolve('')
|
resolve('')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/utils/myEvent.js
Normal file
15
src/utils/myEvent.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class MyEvent {
|
||||||
|
static list = []
|
||||||
|
add(name, call) {
|
||||||
|
MyEvent.list.push({ name, call })
|
||||||
|
}
|
||||||
|
remove(name, call) {
|
||||||
|
MyEvent.list = MyEvent.list.filter(item => item.name != name && item.call != call)
|
||||||
|
}
|
||||||
|
emit(name, data) {
|
||||||
|
MyEvent.list.forEach(item => {
|
||||||
|
if (item.name == name) item.call(data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default new MyEvent()
|
||||||
Reference in New Issue
Block a user