mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
feat(vue-app): support functional watchQuery
(#6222)
This commit is contained in:
parent
8f5244cabd
commit
c6a9b37821
@ -140,15 +140,21 @@ async function loadAsyncComponents(to, from, next) {
|
||||
<% } %>
|
||||
|
||||
try {
|
||||
const Components = await resolveRouteComponents(to)
|
||||
const Components = await resolveRouteComponents(
|
||||
to,
|
||||
(Component, instance) => ({ Component, instance })
|
||||
)
|
||||
<% if (loading) { %>
|
||||
if (!this._pathChanged && this._queryChanged) {
|
||||
// Add a marker on each component that it needs to refresh or not
|
||||
const startLoader = Components.some((Component) => {
|
||||
const startLoader = Components.some(({Component, instance}) => {
|
||||
const watchQuery = Component.options.watchQuery
|
||||
if (watchQuery === true) return true
|
||||
if (Array.isArray(watchQuery)) {
|
||||
if (watchQuery === true) {
|
||||
return true
|
||||
} else if (Array.isArray(watchQuery)) {
|
||||
return watchQuery.some(key => this._diffQuery[key])
|
||||
} else if (typeof watchQuery === 'function') {
|
||||
return watchQuery.apply(instance, [to.query, from.query])
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
@ -98,15 +98,15 @@ export function flatMapComponents(route, fn) {
|
||||
}))
|
||||
}
|
||||
|
||||
export function resolveRouteComponents(route) {
|
||||
export function resolveRouteComponents(route, fn) {
|
||||
return Promise.all(
|
||||
flatMapComponents(route, async (Component, _, match, key) => {
|
||||
flatMapComponents(route, async (Component, instance, match, key) => {
|
||||
// If component is a function, resolve it
|
||||
if (typeof Component === 'function' && !Component.options) {
|
||||
Component = await Component()
|
||||
}
|
||||
match.components[key] = sanitizeComponent(Component)
|
||||
return match.components[key]
|
||||
match.components[key] = Component = sanitizeComponent(Component)
|
||||
return typeof fn === 'function' ? fn(Component, instance, match, key) : Component
|
||||
})
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user