mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 15:09:16 +08:00
[new feature] Sidebar: add to and replace prop (#3696)
This commit is contained in:
parent
514e44e621
commit
531fa6681e
@ -1,6 +1,7 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import Info from '../info';
|
import Info from '../info';
|
||||||
import { ChildrenMixin } from '../mixins/relation';
|
import { ChildrenMixin } from '../mixins/relation';
|
||||||
|
import { route, routeProps } from '../utils/router';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('sidebar-item');
|
const [createComponent, bem] = createNamespace('sidebar-item');
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ export default createComponent({
|
|||||||
mixins: [ChildrenMixin('vanSidebar')],
|
mixins: [ChildrenMixin('vanSidebar')],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
url: String,
|
...routeProps,
|
||||||
info: [String, Number],
|
info: [String, Number],
|
||||||
title: String
|
title: String
|
||||||
},
|
},
|
||||||
@ -23,13 +24,13 @@ export default createComponent({
|
|||||||
onClick() {
|
onClick() {
|
||||||
this.$emit('click', this.index);
|
this.$emit('click', this.index);
|
||||||
this.parent.$emit('change', this.index);
|
this.parent.$emit('change', this.index);
|
||||||
|
route(this.$router, this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
href={this.url}
|
|
||||||
class={[bem({ select: this.select }), 'van-hairline']}
|
class={[bem({ select: this.select }), 'van-hairline']}
|
||||||
onClick={this.onClick}
|
onClick={this.onClick}
|
||||||
>
|
>
|
||||||
|
@ -72,6 +72,8 @@ export default {
|
|||||||
| title | 内容 | `String` | `''` | - |
|
| title | 内容 | `String` | `''` | - |
|
||||||
| info | 提示消息 | `String | Number` | `''` | - |
|
| info | 提示消息 | `String | Number` | `''` | - |
|
||||||
| url | 跳转链接 | `String` | - | - |
|
| url | 跳转链接 | `String` | - | - |
|
||||||
|
| to | 路由跳转对象,同 vue-router 的 to 属性 | `String | Object` | - | 2.0.4 |
|
||||||
|
| replace | 跳转时是否替换当前页面历史 | `Boolean` | `false` | 2.0.4 |
|
||||||
|
|
||||||
### SidebarItem Events
|
### SidebarItem Events
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { mount } from '../../../test/utils';
|
|||||||
import Sidebar from '..';
|
import Sidebar from '..';
|
||||||
import SidebarItem from '../../sidebar-item';
|
import SidebarItem from '../../sidebar-item';
|
||||||
|
|
||||||
test('event', () => {
|
test('click event & change event', () => {
|
||||||
const onClick = jest.fn();
|
const onClick = jest.fn();
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user