Router 导航路由
基础用法
{
"type": "router",
"resources": {
"routerRes": {
"api": {
"prefix": "https://easy-mock.com/mock/5a0023effbbb09615044cb82/",
"read": "read"
},
"fields": {
"testDate": {
"type": "date",
"label": "日期"
},
"testSwitch": {
"type": "switch",
"label": "开关"
}
}
}
},
"router": {
"routes": [{
"path": "",
"name": "首页",
"block": "formEditAll",
"meta": {
"icon": "menu"
}
}, {
"path": "/list",
"name": "列表页",
"block": "listComponent"
}]
},
"blocks": {
"formEditAll": {
"type": "form",
"resource": "routerRes",
"ctx": "edit",
"style": {
"width": "50%"
},
"data": {
"testRadio": "c"
},
"events": {
"init": "@read",
"submit": "@validate @update"
},
"operations": {
"submit": {
"type": "button",
"event": "submit",
"label": "提交",
"props": {
"type": "primary"
}
}
}
},
"listComponent": {
"type": "component",
"options": {
"is": "div",
"text": "我是插进来的TEXT内容",
"html": "<h3>我是插进来的HTML内容</h3>"
}
}
}
}
显示配置
slotBlocks 配置
菜单头部slot block
配置子block的slot为menuTop
,可以插入在菜单头部
{
"type": "router",
"router": {
"routes": [{
"path": "",
"name": "首页",
"block": "listComponent",
"meta": {
"icon": "menu"
}
}]
},
"blocks": {
"listComponent": {
"type": "component",
"options": {
"is": "div",
"text": "我是插进来的TEXT内容",
"html": "<h3>我是插进来的HTML内容</h3>"
}
},
"title1": {
"type": "component",
"options": {
"is": "h3",
"text": "AMS系统"
},
"style": {
"color": "#fff",
"text-align": "center"
},
"slot": "menuTop"
}
}
}
显示配置
菜单底部slot block
配置子block的slot为menuBottom
,可以插入在菜单底部
{
"type": "router",
"router": {
"routes": [{
"path": "",
"name": "首页",
"block": "listComponent",
"meta": {
"icon": "menu"
}
}, {
"path": "/menu1",
"name": "菜单一",
"meta": {
"icon": "user-solid"
},
"children": [{
"name": "子菜单",
"path": "path1_0",
"block": "listComponent"
}]
}, {
"path": "/menu2",
"name": "菜单二",
"block": "listComponent",
"meta": {
"icon": "star-on"
}
}, {
"path": "/menu3",
"name": "菜单三",
"block": "listComponent",
"meta": {
"icon": "s-help"
}
}]
},
"blocks": {
"listComponent": {
"type": "component",
"options": {
"is": "div",
"text": "我是插进来的TEXT内容",
"html": "<h3>我是插进来的HTML内容</h3>"
}
},
"menuBottomtext": {
"type": "component",
"options": {
"is": "div",
"text": "Copyright © 2008-2019 vip.com"
},
"style": {
"color": "#aaa",
"padding": "10px",
"margin-top": "100px",
"font-size": "12px"
},
"slot": "menuBottom"
}
}
}
显示配置
导航的位置slot block
配置子block的slot为nav
,可以插入在导航的位置。比如下面例子插入了两个操作按钮“反馈”和“帮助”。
{
"type": "router",
"router": {
"routes": [{
"path": "",
"name": "首页",
"block": "listComponent",
"meta": {
"icon": "menu"
}
}]
},
"blocks": {
"listComponent": {
"type": "component",
"options": {
"is": "div",
"text": "我是插进来的TEXT内容",
"html": "<h3>我是插进来的HTML内容</h3>"
}
},
"title1": {
"type": "component",
"options": {
"is": "h3",
"text": "AMS系统"
},
"style": {
"color": "#fff",
"text-align": "center"
},
"slot": "menuTop"
},
"navRouterTitle": {
"type": "component",
"options": {
"is": "div"
},
"operations": {
"feedback": {
"type": "button",
"label": "反馈",
"style": {
"margin-top": "5px",
"margin-right": "15px"
},
"props": {
"type": "text",
"icon": "el-icon-document",
"size": "large"
}
},
"help": {
"type": "button",
"label": "帮助",
"style": {
"margin-top": "5px"
},
"props": {
"type": "text",
"icon": "el-icon-question",
"size": "large"
}
}
},
"actions": {
"feedback": function() {
window.location.href = "https://github.com/vipshop/ams/issues"
},
"help": function() {
window.location.href = "https://github.com/vipshop/ams"
}
},
"slot": "nav"
}
}
}
显示配置
在线实验室
参数列表
参数 | 说明 | 可选值 | 类型 | 必填 |
---|
type | block类型 | string | 是 |
data | data可以指定当前block的初始数据,结构和fields保持一致 | null | object | 否 |
config | 全局配置,和通过ams.config配置效果一致 | null | object | 否 |
style | 可以设置区块的外层样式 | null | object | 否 |
events | 可以配置对应事件的处理actions | null | object | 否 |
actions | 可以配置具体的action处理函数 | null | object | 否 |
operations | 可以配置operation操作 | null | object | 否 |
blocks | 可以配置多个子block | null | object | 否 |
render | 默认为false,配置为true则自动在body内渲染,如传入string则渲染在指定的querySelector上 | boolean | string | 否 |
props | 会透传至底层的element-ui组件作为props属性,或者是原生dom元素的属性 | null | object | 否 |
options | block特有配置 | null | object | 否 |
router | 可以配置菜单和页面路由 | null | object | 否 |
结构
export interface Route {
path: string, // 路由地址
name: string, // 路由名
block?: string, // 渲染block名
redirect?: string, // 重定向地址
children?: Array<Route>, // 子路由
meta?: {
icon?: string, // 对应的图标:参考http://element-cn.eleme.io/#/zh-CN/component/icon,如 'info' 对应 'el-icon-info'
hasMenu?: boolean, // 是否显示导航菜单面包屑,默认true
hidden?: boolean, // 是否在左侧导航菜单显示,默认false
roles?: Array<string>, // 路由权限角色,data内包含对应的角色才可见改路由
noRedirect?: boolean, // 对应面包屑是否禁用跳转,默认为false
}
}
export interface RouterBlock {
type: 'router',
router: {
mode?: "hash" | "history" | "abstract",
base?: "string", // 更多选项参考:https://router.vuejs.org/zh/api/#linkexactactiveclass
showMenu?: true | false, // 默认为true, false时隐藏所有路由菜单 0.8.6+支持
routes: Array<Route>,
defaultBreadcrumb: true // 默认为true,会把首个route作为默认首页加到所有面包屑,设置为false禁用此行为, 0.7.5+支持
},
data?: {
roles?: Array<string> // 当前用户权限角色,用户需要包含路由要求的roles权限才能看到对应菜单
},
on?: {
// 这里可以在生成router实例时注册事件,如beforeEach,详见 [ Router 实例方法 ](https://router.vuejs.org/zh/api/#router-%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95)
}
}