[improvement] Tabbar: jsx (#2663)

This commit is contained in:
neverland
2019-02-01 17:10:31 +08:00
committed by GitHub
parent 5b3992d4c2
commit b8ec2ffc5d
6 changed files with 85 additions and 102 deletions

View File

@@ -0,0 +1,54 @@
import { use, useSlots } from '../utils';
import Icon from '../icon';
import Info from '../info';
import RouterLink from '../mixins/router-link';
const [sfc, bem] = use('tabbar-item');
export default sfc({
mixins: [RouterLink],
props: {
icon: String,
dot: Boolean,
info: [String, Number]
},
data() {
return {
active: false
};
},
beforeCreate() {
this.$parent.items.push(this);
},
destroyed() {
this.$parent.items.splice(this.$parent.items.indexOf(this), 1);
},
methods: {
onClick(event) {
this.$parent.onChange(this.$parent.items.indexOf(this));
this.$emit('click', event);
this.routerLink();
}
},
render(h) {
const { icon, active } = this;
const slots = useSlots(this);
const style = active ? { color: this.$parent.activeColor } : null;
return (
<div class={bem({ active })} style={style} onClick={this.onClick}>
<div class={bem('icon', { dot: this.dot })}>
{slots('icon', { active }) || (icon && <Icon name={icon} />)}
<Info info={this.info} />
</div>
<div class={bem('text')}>{slots('default', { active })}</div>
</div>
);
}
});

View File

@@ -1,73 +0,0 @@
<template>
<div
:class="b({ active })"
:style="style"
@click="onClick"
>
<div :class="b('icon', { dot })">
<slot
name="icon"
:active="active"
>
<icon
v-if="icon"
:name="icon"
/>
</slot>
<van-info :info="info" />
</div>
<div :class="b('text')">
<slot :active="active" />
</div>
</div>
</template>
<script>
import Info from '../info';
import create from '../utils/create';
import RouterLink from '../mixins/router-link';
export default create({
name: 'tabbar-item',
components: {
[Info.name]: Info
},
mixins: [RouterLink],
props: {
icon: String,
dot: Boolean,
info: [String, Number]
},
data() {
return {
active: false
};
},
computed: {
style() {
return this.active ? { color: this.$parent.activeColor } : null;
}
},
beforeCreate() {
this.$parent.items.push(this);
},
destroyed() {
this.$parent.items.splice(this.$parent.items.indexOf(this), 1);
},
methods: {
onClick(event) {
this.$parent.onChange(this.$parent.items.indexOf(this));
this.$emit('click', event);
this.routerLink();
}
}
});
</script>