We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在类似于下拉菜单分组的时候,往往会出现items嵌套层级比较深,不好进一步扩展维护
我已经写好了demo,并且在vitepress源码中已经更改,但本人由于第一次pr,不太会使用,在这附上一些代码片段,以及使用示例。 `import type { DefaultTheme } from 'vitepress' const handleData = [ { id: 0, text: '学习心得1', children: [ { groupId: '0-0', text: '学习心得2', link: 'xxx', }, { groupId: '0-0', text: '学习心得3', link: 'xxx', }, { groupId: '0-1', text: '学习心得4', link: 'xxx', }, { groupId: '0-2', text: '学习心得5', link: 'xxx', }, { groupId: '0-3', text: '学习心得6', link: 'xxx', }, ], }, { id: 1, text: '学习心得1', children: [ { groupId: '1-1', text: '学习心得2', link: 'xxx', }, { groupId: '1-2', text: '学习心得3', link: 'xxx', }, { groupId: '1-3', text: '学习心得4', link: 'xxx', }, ], }, ]
function transformHandleDataToNav(handleData) { return handleData.map((dataItem) => { // 创建顶级nav项 const navItem = { text: dataItem.text, items: [] }
// 如果有子项,根据groupId进行分组 if (dataItem.children) { const groups = new Map() dataItem.children.forEach((child) => { const groupId = child.groupId.split('-')[1] // 假设groupId格式为"id-index" if (!groups.has(groupId)) { groups.set(groupId, []) } groups.get(groupId).push({ text: child.text, link: child.link }) }) // 将分组转换为items数组 groups.forEach((groupItems) => { navItem.items.push({ items: groupItems }) }) } else if (dataItem.link) { // 如果没有子项但有链接,直接设置链接 navItem.link = dataItem.link } return navItem
}) }
const nav1 = transformHandleDataToNav(handleData) console.log(nav1)
export const nav: DefaultTheme.Config['nav'] = nav1 `,在这个示例中,我们可以清晰的配置navGroup选项,只需要在groupid去配置,以"id-index"手动式声明,当然也可以在runtime时编译 添加id之类的。
No response
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
我也这么希望,兄嘚
Duplicate of #3816
在开发完成前,如果定义需求可以这样玩: https://vitepress.dev/guide/extending-default-theme#overriding-internal-components
No branches or pull requests
Is your feature request related to a problem? Please describe.
在类似于下拉菜单分组的时候,往往会出现items嵌套层级比较深,不好进一步扩展维护
Describe the solution you'd like
我已经写好了demo,并且在vitepress源码中已经更改,但本人由于第一次pr,不太会使用,在这附上一些代码片段,以及使用示例。
`import type { DefaultTheme } from 'vitepress'
const handleData = [
{
id: 0,
text: '学习心得1',
children: [
{
groupId: '0-0',
text: '学习心得2',
link: 'xxx',
},
{
groupId: '0-0',
text: '学习心得3',
link: 'xxx',
},
{
groupId: '0-1',
text: '学习心得4',
link: 'xxx',
},
{
groupId: '0-2',
text: '学习心得5',
link: 'xxx',
},
{
groupId: '0-3',
text: '学习心得6',
link: 'xxx',
},
],
},
{
id: 1,
text: '学习心得1',
children: [
{
groupId: '1-1',
text: '学习心得2',
link: 'xxx',
},
{
groupId: '1-2',
text: '学习心得3',
link: 'xxx',
},
{
groupId: '1-3',
text: '学习心得4',
link: 'xxx',
},
],
},
]
function transformHandleDataToNav(handleData) {
return handleData.map((dataItem) => {
// 创建顶级nav项
const navItem = { text: dataItem.text, items: [] }
})
}
const nav1 = transformHandleDataToNav(handleData)
console.log(nav1)
export const nav: DefaultTheme.Config['nav'] = nav1
`,在这个示例中,我们可以清晰的配置navGroup选项,只需要在groupid去配置,以"id-index"手动式声明,当然也可以在runtime时编译
添加id之类的。
Describe alternatives you've considered
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: