mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 03:44:48 +00:00
[improvement] Tabbar: jsx (#2663)
This commit is contained in:
60
packages/tabbar/index.js
Normal file
60
packages/tabbar/index.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import { use } from '../utils';
|
||||
|
||||
const [sfc, bem] = use('tabbar');
|
||||
|
||||
export default sfc({
|
||||
data() {
|
||||
return {
|
||||
items: []
|
||||
};
|
||||
},
|
||||
|
||||
props: {
|
||||
value: Number,
|
||||
activeColor: String,
|
||||
fixed: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
zIndex: {
|
||||
type: Number,
|
||||
default: 1
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
items() {
|
||||
this.setActiveItem();
|
||||
},
|
||||
|
||||
value() {
|
||||
this.setActiveItem();
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
setActiveItem() {
|
||||
this.items.forEach((item, index) => {
|
||||
item.active = index === this.value;
|
||||
});
|
||||
},
|
||||
|
||||
onChange(active) {
|
||||
if (active !== this.value) {
|
||||
this.$emit('input', active);
|
||||
this.$emit('change', active);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
render(h) {
|
||||
return (
|
||||
<div
|
||||
style={{ zIndex: this.zIndex }}
|
||||
class={['van-hairline--top-bottom', bem({ fixed: this.fixed })]}
|
||||
>
|
||||
{this.$slots.default}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user