mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate Tabbar component
This commit is contained in:
parent
75421a4727
commit
7fda2659f5
@ -37,4 +37,6 @@ module.exports = [
|
|||||||
'share-sheet',
|
'share-sheet',
|
||||||
'pull-refresh',
|
'pull-refresh',
|
||||||
'field',
|
'field',
|
||||||
|
'tabbar',
|
||||||
|
'tabbar-item',
|
||||||
];
|
];
|
||||||
|
@ -24,6 +24,8 @@ export default createComponent({
|
|||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['click'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
active: false,
|
active: false,
|
||||||
@ -51,10 +53,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
genIcon(active) {
|
genIcon(active) {
|
||||||
const slot = this.slots('icon', { active });
|
if (this.$slots.icon) {
|
||||||
|
return this.$slots.icon({ active });
|
||||||
if (slot) {
|
|
||||||
return slot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.icon) {
|
if (this.icon) {
|
||||||
@ -76,7 +76,9 @@ export default createComponent({
|
|||||||
info={isDef(this.badge) ? this.badge : this.info}
|
info={isDef(this.badge) ? this.badge : this.info}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class={bem('text')}>{this.slots('default', { active })}</div>
|
<div class={bem('text')}>
|
||||||
|
{this.$slots.default ? this.$slots.default({ active }) : null}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@ export default createComponent({
|
|||||||
placeholder: Boolean,
|
placeholder: Boolean,
|
||||||
activeColor: String,
|
activeColor: String,
|
||||||
inactiveColor: String,
|
inactiveColor: String,
|
||||||
value: {
|
modelValue: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
@ -31,6 +31,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['change', 'update:modelValue'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
height: null,
|
height: null,
|
||||||
@ -48,8 +50,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
value: 'setActiveItem',
|
|
||||||
children: 'setActiveItem',
|
children: 'setActiveItem',
|
||||||
|
modelValue: 'setActiveItem',
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -61,13 +63,13 @@ export default createComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
setActiveItem() {
|
setActiveItem() {
|
||||||
this.children.forEach((item, index) => {
|
this.children.forEach((item, index) => {
|
||||||
item.active = (item.name || index) === this.value;
|
item.active = (item.name || index) === this.modelValue;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(active) {
|
onChange(active) {
|
||||||
if (active !== this.value) {
|
if (active !== this.modelValue) {
|
||||||
this.$emit('input', active);
|
this.$emit('update:modelValue', active);
|
||||||
this.$emit('change', active);
|
this.$emit('change', active);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -85,7 +87,7 @@ export default createComponent({
|
|||||||
}),
|
}),
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{this.slots()}
|
{this.$slots.default?.()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -310,10 +310,10 @@ module.exports = {
|
|||||||
// path: 'tab',
|
// path: 'tab',
|
||||||
// title: 'Tab 标签页',
|
// title: 'Tab 标签页',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'tabbar',
|
path: 'tabbar',
|
||||||
// title: 'Tabbar 标签栏',
|
title: 'Tabbar 标签栏',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
path: 'tree-select',
|
path: 'tree-select',
|
||||||
title: 'TreeSelect 分类选择',
|
title: 'TreeSelect 分类选择',
|
||||||
@ -644,10 +644,10 @@ module.exports = {
|
|||||||
// path: 'tab',
|
// path: 'tab',
|
||||||
// title: 'Tab',
|
// title: 'Tab',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'tabbar',
|
path: 'tabbar',
|
||||||
// title: 'Tabbar',
|
title: 'Tabbar',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
path: 'tree-select',
|
path: 'tree-select',
|
||||||
title: 'TreeSelect',
|
title: 'TreeSelect',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user