Files
vant/src/tabbar/index.js
2019-08-09 14:15:49 +08:00

70 lines
1.3 KiB
JavaScript

import { createNamespace } from '../utils';
import { ParentMixin } from '../mixins/relation';
import { BORDER_TOP_BOTTOM } from '../utils/constant';
const [createComponent, bem] = createNamespace('tabbar');
export default createComponent({
mixins: [ParentMixin('vanTabbar')],
props: {
route: Boolean,
activeColor: String,
inactiveColor: String,
safeAreaInsetBottom: Boolean,
value: {
type: [Number, String],
default: 0
},
border: {
type: Boolean,
default: true
},
fixed: {
type: Boolean,
default: true
},
zIndex: {
type: Number,
default: 1
}
},
watch: {
value: 'setActiveItem',
children: 'setActiveItem'
},
methods: {
setActiveItem() {
this.children.forEach((item, index) => {
item.active = (item.name || index) === this.value;
});
},
onChange(active) {
if (active !== this.value) {
this.$emit('input', active);
this.$emit('change', active);
}
}
},
render() {
return (
<div
style={{ zIndex: this.zIndex }}
class={[
{ [BORDER_TOP_BOTTOM]: this.border },
bem({
fixed: this.fixed,
'safe-area-inset-bottom': this.safeAreaInsetBottom
})
]}
>
{this.slots()}
</div>
);
}
});