mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
fix(service-layout): sync path on options change
This commit is contained in:
parent
ab1d9de7f9
commit
3b432881ad
@ -315,6 +315,8 @@ export const routes = [
|
||||
{
|
||||
name: 'site',
|
||||
path: '/:lang/:theme',
|
||||
// Keep the wrapper router view, since if not the route won't be initialized
|
||||
// after them site is mounted (no matched route)
|
||||
component: Site,
|
||||
children: [
|
||||
{
|
||||
|
@ -67,9 +67,12 @@ export default defineComponent({
|
||||
return createItems(props.items)
|
||||
})
|
||||
if (route) {
|
||||
syncValue(route.path)
|
||||
syncPath(route.path)
|
||||
watch(toRef(route, 'path'), (path) => {
|
||||
syncValue(path)
|
||||
syncPath(path)
|
||||
})
|
||||
watch(toRef(props, 'items'), () => {
|
||||
syncPath(route.path)
|
||||
})
|
||||
}
|
||||
function doUpdateCollapsed (value: boolean): void {
|
||||
@ -94,11 +97,11 @@ export default defineComponent({
|
||||
const scrollTo: LayoutRef['scrollTo'] = (...args: any[]): void => {
|
||||
;(bodyLayoutInstRef.value?.scrollTo as Function)(...args)
|
||||
}
|
||||
function syncValue (path?: string, items?: Item[]): void {
|
||||
function syncPath (path?: string, items?: Item[]): void {
|
||||
if (items === undefined) items = props.items
|
||||
for (const item of items) {
|
||||
if (item.childItems || item.children) {
|
||||
syncValue(path, item.childItems || item.children)
|
||||
syncPath(path, item.childItems || item.children)
|
||||
} else if (item.path === path) {
|
||||
doUpdateValue(item.name || item.key || '')
|
||||
return
|
@ -2,13 +2,15 @@ import * as components from './components'
|
||||
import { enUS, zhCN } from './locales'
|
||||
|
||||
// deprecated
|
||||
import { NServiceLayout } from './_deprecated/nimbus-service-layout/index'
|
||||
import { NServiceLayout } from './_deprecated/service-layout/index'
|
||||
|
||||
import create from './create'
|
||||
|
||||
export default create({
|
||||
components: [
|
||||
...Object.keys(components).map((key) => components[key as keyof typeof components]),
|
||||
...Object.keys(components).map(
|
||||
(key) => components[key as keyof typeof components]
|
||||
),
|
||||
// Deprecated
|
||||
NServiceLayout
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user