Files
Code-Create/src/stores/global.ts

20 lines
522 B
TypeScript
Raw Normal View History

2026-05-18 15:22:08 +08:00
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export const useGlobalStore = defineStore('global', () => {
const state = ref({
loading: false,// 全局loading
2026-06-04 10:47:16 +08:00
windowWidth: 1920,// 页面宽度
2026-05-18 15:22:08 +08:00
})
const setLoading = (v: boolean) => { state.value.loading = v }
return {
state,
setLoading,
}
})
2026-06-04 10:47:16 +08:00
function setWindowWidth() {
return useGlobalStore().state.windowWidth = window.innerWidth
}
window.addEventListener('resize', setWindowWidth)
window.addEventListener('load', setWindowWidth)