feat: migrate Tabbar component
This commit is contained in:
@@ -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>
|
||||
);
|
||||
},
|
||||
|
||||
+8
-6
@@ -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>
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user