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',
|
||||
'pull-refresh',
|
||||
'field',
|
||||
'tabbar',
|
||||
'tabbar-item',
|
||||
];
|
||||
|
@ -24,6 +24,8 @@ export default createComponent({
|
||||
iconPrefix: String,
|
||||
},
|
||||
|
||||
emits: ['click'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
active: false,
|
||||
@ -51,10 +53,8 @@ export default createComponent({
|
||||
},
|
||||
|
||||
genIcon(active) {
|
||||
const slot = this.slots('icon', { active });
|
||||
|
||||
if (slot) {
|
||||
return slot;
|
||||
if (this.$slots.icon) {
|
||||
return this.$slots.icon({ active });
|
||||
}
|
||||
|
||||
if (this.icon) {
|
||||
@ -76,7 +76,9 @@ export default createComponent({
|
||||
info={isDef(this.badge) ? this.badge : this.info}
|
||||
/>
|
||||
</div>
|
||||
<div class={bem('text')}>{this.slots('default', { active })}</div>
|
||||
<div class={bem('text')}>
|
||||
{this.$slots.default ? this.$slots.default({ active }) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ export default createComponent({
|
||||
placeholder: Boolean,
|
||||
activeColor: String,
|
||||
inactiveColor: String,
|
||||
value: {
|
||||
modelValue: {
|
||||
type: [Number, String],
|
||||
default: 0,
|
||||
},
|
||||
@ -31,6 +31,8 @@ export default createComponent({
|
||||
},
|
||||
},
|
||||
|
||||
emits: ['change', 'update:modelValue'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
height: null,
|
||||
@ -48,8 +50,8 @@ export default createComponent({
|
||||
},
|
||||
|
||||
watch: {
|
||||
value: 'setActiveItem',
|
||||
children: 'setActiveItem',
|
||||
modelValue: 'setActiveItem',
|
||||
},
|
||||
|
||||
mounted() {
|
||||
@ -61,13 +63,13 @@ export default createComponent({
|
||||
methods: {
|
||||
setActiveItem() {
|
||||
this.children.forEach((item, index) => {
|
||||
item.active = (item.name || index) === this.value;
|
||||
item.active = (item.name || index) === this.modelValue;
|
||||
});
|
||||
},
|
||||
|
||||
onChange(active) {
|
||||
if (active !== this.value) {
|
||||
this.$emit('input', active);
|
||||
if (active !== this.modelValue) {
|
||||
this.$emit('update:modelValue', active);
|
||||
this.$emit('change', active);
|
||||
}
|
||||
},
|
||||
@ -85,7 +87,7 @@ export default createComponent({
|
||||
}),
|
||||
]}
|
||||
>
|
||||
{this.slots()}
|
||||
{this.$slots.default?.()}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
@ -310,10 +310,10 @@ module.exports = {
|
||||
// path: 'tab',
|
||||
// title: 'Tab 标签页',
|
||||
// },
|
||||
// {
|
||||
// path: 'tabbar',
|
||||
// title: 'Tabbar 标签栏',
|
||||
// },
|
||||
{
|
||||
path: 'tabbar',
|
||||
title: 'Tabbar 标签栏',
|
||||
},
|
||||
{
|
||||
path: 'tree-select',
|
||||
title: 'TreeSelect 分类选择',
|
||||
@ -644,10 +644,10 @@ module.exports = {
|
||||
// path: 'tab',
|
||||
// title: 'Tab',
|
||||
// },
|
||||
// {
|
||||
// path: 'tabbar',
|
||||
// title: 'Tabbar',
|
||||
// },
|
||||
{
|
||||
path: 'tabbar',
|
||||
title: 'Tabbar',
|
||||
},
|
||||
{
|
||||
path: 'tree-select',
|
||||
title: 'TreeSelect',
|
||||
|
Loading…
x
Reference in New Issue
Block a user