ant-design-vue
ant-design-vue copied to clipboard
template API 例子太少
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Version
4.0.7
Environment
中國
Reproduction link
https://www.antdv.com/components/menu#api
Steps to reproduce
官網的示例代碼,幾乎都是:options這種API,而template API的例子少得可憐。menu這個頁面,一個template API的例子都沒有,到底還支不支持這種API啊?如果不支持,應該說明一下吧?
我看了ant-design-vue的文檔,2到3,3到4,都沒有廢除menu的template API,既然如此,官網為什麼沒有例子?
官网这种API,不用template来定义menu,而是绑定一个items的数组,而数组里面是用一个叫h的函数来渲染DOM。
這種方式,把业务上的逻辑层次结构和页面渲染耦合在一起了。Vue的设计就是要把data跟view進行分離,ant 这种设计,不是與之背道而驰嗎?一個在進行耦合,一個在進行解耦。
假如,这个items數組很长,有三千行,我想单独用一个文件放置,比如menu-data.js。因为数组里面还有用h函数进行渲染的逻辑,这个文件还得引入一些component才行:
menu-data.js:
import many-many-components from "lib"
export default [
{
label: h(Comp),
name: 'Comp'
}
]
一個純粹只想定義層次結構的文件,裡面引入一對components,不奇怪嗎?
找找自己的原因,h函数是vue提供的另一种渲染组件的api , 如果你会写jsx,那么你可以将h(Comp) 变成 <Comp /> , 效果是一样的, 这种写法的好处就是不再束缚要渲染的地方是字符串还是组件 , 增加灵活性
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days
确实。一个例子都没有,不过可以看看v3的示例。用一个items的好处是,不必自己写递归组件了~