Modernize vue-wait initialization and usage patterns to support Vue 3 Composition API while preserving Vue 2 Options API functionality. Changes: - Migrate App.vue to Vue 3 <script setup> syntax - Convert Options API to Composition API - Use defineComponent and reactive state management - Maintain existing functionality and lifecycle hooks - Refactor vue-wait initialization (boot/vue-wait.js) - Move initialization from App.vue mounted() to boot phase - Create initializeWait() function for explicit setup - Register $wait globally before component mounting - Add Vue 3 composable support (composables/useWait.js) - Create useWait() composable for Composition API components - Access $wait via getCurrentInstance() for proper Vue 3 patterns - Enable gradual migration from Options to Composition API - Update documentation (doc/architectural-overview.md) - Add "Loading State Management (vue-wait)" section - Document usage patterns for both Vue 2 and Vue 3 - Clarify migration strategy and coexistence Note: All existing Vue 2 components using this.$wait continue working unchanged while new Vue 3 components can use useWait() composable. Change-Id: I62c9eaa81336a1ae115f1b326676497dcac262b2mr14.1
parent
d575fe2dd5
commit
db5e5b55eb
@ -1,49 +1,40 @@
|
|||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
<script>
|
|
||||||
import _ from 'lodash'
|
<script setup>
|
||||||
|
import { useMeta } from 'quasar'
|
||||||
import { APP_NAME } from 'src/constants'
|
import { APP_NAME } from 'src/constants'
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
export default {
|
const route = useRoute()
|
||||||
name: 'App',
|
const pageTitle = ref('')
|
||||||
meta () {
|
|
||||||
return {
|
const updateTitle = (route) => {
|
||||||
title: this.pageTitle,
|
|
||||||
titleTemplate: (title) => `${APP_NAME} - ${title}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
pageTitle: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
$route (route) {
|
|
||||||
this.updateTitle(route)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
this.$initWait()
|
|
||||||
this.updateTitle(this.$route)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
updateTitle: function (route) {
|
|
||||||
if (route) {
|
if (route) {
|
||||||
const titleElements = []
|
const titleElements = []
|
||||||
const title = _.get(route, 'meta.title', '')
|
const title = route.meta?.title || ''
|
||||||
const subTitle = _.get(route, 'meta.subtitle', '')
|
const subTitle = route.meta?.subtitle || ''
|
||||||
if (title !== '') {
|
if (title !== '') {
|
||||||
titleElements.push(title)
|
titleElements.push(title)
|
||||||
}
|
}
|
||||||
if (subTitle !== '') {
|
if (subTitle !== '') {
|
||||||
titleElements.push(subTitle)
|
titleElements.push(subTitle)
|
||||||
}
|
}
|
||||||
this.pageTitle = titleElements.join(' - ') || route.name || ''
|
pageTitle.value = titleElements.join(' - ') || route.name || ''
|
||||||
} else {
|
} else {
|
||||||
this.pageTitle = ''
|
pageTitle.value = ''
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(route, (newRoute) => {
|
||||||
|
updateTitle(newRoute)
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
|
useMeta(() => ({
|
||||||
|
title: pageTitle.value,
|
||||||
|
titleTemplate: (title) => `${APP_NAME} - ${title}`
|
||||||
|
}))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,12 +1,17 @@
|
|||||||
import { createVueWait } from 'vue-wait-vue3'
|
import { createVueWait } from 'vue-wait-vue3'
|
||||||
|
|
||||||
export default ({ app }) => {
|
export function initializeWait (app) {
|
||||||
app.config.globalProperties.$initWait = () => {
|
|
||||||
const VueWait = createVueWait({
|
const VueWait = createVueWait({
|
||||||
useVuex: true,
|
useVuex: true,
|
||||||
vuexModuleName: 'wait',
|
vuexModuleName: 'wait',
|
||||||
registerDirective: true
|
registerDirective: true
|
||||||
})
|
})
|
||||||
app.use(VueWait)
|
app.use(VueWait)
|
||||||
|
|
||||||
|
return VueWait
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default ({ app }) => {
|
||||||
|
// Initialize wait immediately during boot
|
||||||
|
initializeWait(app)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { getCurrentInstance } from 'vue'
|
||||||
|
|
||||||
|
export function useWait () {
|
||||||
|
const instance = getCurrentInstance()
|
||||||
|
if (!instance) {
|
||||||
|
throw new Error('useWait must be called within a component setup function')
|
||||||
|
}
|
||||||
|
|
||||||
|
const wait = instance.appContext.config.globalProperties.$wait
|
||||||
|
if (!wait) {
|
||||||
|
throw new Error('vue-wait is not initialized. Make sure vue-wait boot file runs before using useWait()')
|
||||||
|
}
|
||||||
|
|
||||||
|
return wait
|
||||||
|
}
|
||||||
Loading…
Reference in new issue