mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-19 02:17:26 +08:00
feat: 处理编译问题
This commit is contained in:
74
frontend_nuxt/composables/useToast.js
Normal file
74
frontend_nuxt/composables/useToast.js
Normal file
@@ -0,0 +1,74 @@
|
||||
// 导出一个便捷的 toast 对象
|
||||
export const toast = {
|
||||
success: async (message) => {
|
||||
if (process.client) {
|
||||
try {
|
||||
const { useToast } = await import('vue-toastification')
|
||||
const toastInstance = useToast()
|
||||
toastInstance.success(message)
|
||||
} catch (error) {
|
||||
console.warn('Toast not available:', error)
|
||||
}
|
||||
}
|
||||
},
|
||||
error: async (message) => {
|
||||
if (process.client) {
|
||||
try {
|
||||
const { useToast } = await import('vue-toastification')
|
||||
const toastInstance = useToast()
|
||||
toastInstance.error(message)
|
||||
} catch (error) {
|
||||
console.warn('Toast not available:', error)
|
||||
}
|
||||
}
|
||||
},
|
||||
warning: async (message) => {
|
||||
if (process.client) {
|
||||
try {
|
||||
const { useToast } = await import('vue-toastification')
|
||||
const toastInstance = useToast()
|
||||
toastInstance.warning(message)
|
||||
} catch (error) {
|
||||
console.warn('Toast not available:', error)
|
||||
}
|
||||
}
|
||||
},
|
||||
info: async (message) => {
|
||||
if (process.client) {
|
||||
try {
|
||||
const { useToast } = await import('vue-toastification')
|
||||
const toastInstance = useToast()
|
||||
toastInstance.info(message)
|
||||
} catch (error) {
|
||||
console.warn('Toast not available:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出 useToast composable
|
||||
export const useToast = () => {
|
||||
if (process.client) {
|
||||
return new Promise(async (resolve) => {
|
||||
try {
|
||||
const { useToast: useVueToast } = await import('vue-toastification')
|
||||
resolve(useVueToast())
|
||||
} catch (error) {
|
||||
console.warn('Toast not available:', error)
|
||||
resolve({
|
||||
success: () => {},
|
||||
error: () => {},
|
||||
warning: () => {},
|
||||
info: () => {}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
success: () => {},
|
||||
error: () => {},
|
||||
warning: () => {},
|
||||
info: () => {}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user