在Vue

时间:2018-02-02 19:34:03

标签: vue.js vue-router

对于像/chart/:charttype

这样的路线感到好奇

我想将不同类型的图表组件加载到该图表区域,如何在VueRouter中规划此(目前我只将/chart/:charttype放在那里)和组件(目前我放了一个容器那里有一个组件,里面有一长串v-if不同类型的图表组件)?任何最佳做法?

/*
    Say I have a long list of diff type of charts, 
    when charttype matches, it will load that component, 
    otherwise load 404 component there. 
*/


 _______________________
 |    _____________    |
 |    |           |    |
 |    |   chart   |    |
 |    |___________|    |
 |_____________________|

我相信当前很长的v-if方式列表将非常难以维护,未来,该图表区域将是一组构建组合图表组件的图表(例如4个图表作为组合图表组件),所以我想必须有一种可配置的方法来做到这一点。

谢谢,

1 个答案:

答案 0 :(得分:3)

您可以在文档中查看Dynamic Components

<component :is="componentName"></component>