123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import baseComponent from '../helpers/baseComponent'
- import classNames from '../helpers/classNames'
- baseComponent({
- relations: {
- '../tabbar/index': {
- type: 'parent',
- },
- },
- properties: {
- prefixCls: {
- type: String,
- value: 'wux-tabbar-item',
- },
- key: {
- type: String,
- value: '',
- },
- title: {
- type: String,
- value: '',
- },
- disabled: {
- type: Boolean,
- value: false,
- },
- },
- data: {
- width: '100%',
- current: false,
- index: '0',
- },
- computed: {
- classes() {
- const { prefixCls, theme, current, disabled } = this.data
- const wrap = classNames(prefixCls, {
- [`${prefixCls}--${theme}`]: theme,
- [`${prefixCls}--current`]: current,
- [`${prefixCls}--disabled`]: disabled,
- })
- const icon = `${prefixCls}__icon`
- const title = `${prefixCls}__title`
- return {
- wrap,
- icon,
- title,
- }
- },
- },
- methods: {
- changeCurrent(current, index, theme, length) {
- const width = 100 / length + '%'
- this.setData({
- width,
- current,
- theme,
- index,
- })
- },
- onTap() {
- const { index, disabled } = this.data
- const parent = this.getRelationNodes('../tabbar/index')[0]
- if (disabled || !parent) {
- return false
- }
- this.triggerEvent('click', { index })
- parent.setActiveKey(index)
- },
- },
- })
|