mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
parent
b98a624960
commit
639d3a65c5
@ -15,12 +15,21 @@
|
|||||||
},
|
},
|
||||||
disabled: Boolean
|
disabled: Boolean
|
||||||
},
|
},
|
||||||
beforeCreate() {
|
data() {
|
||||||
this.$parent.tabs.push(this);
|
const nextIndex = this.$parent.tabs.length;
|
||||||
|
this.$parent.tabs.push({
|
||||||
|
title: this.title,
|
||||||
|
disabled: this.disabled,
|
||||||
|
index: nextIndex
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: nextIndex
|
||||||
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
classNames() {
|
classNames() {
|
||||||
return { 'van-tab__pane--select': this.$parent.tabs.indexOf(this) === this.$parent.curActive };
|
return { 'van-tab__pane--select': this.key === this.$parent.curActive };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<van-tabs :active="active">
|
<van-tabs :active="active" @click="handleTabClick" @disabled="handleTabDisabledClick">
|
||||||
<van-tab title="选项一">内容一</van-tab>
|
<van-tab title="选项一">内容一</van-tab>
|
||||||
<van-tab title="选项二">内容二</van-tab>
|
<van-tab title="选项二">内容二</van-tab>
|
||||||
<van-tab title="选项三" disabled>内容三</van-tab>
|
<van-tab title="选项三" disabled>内容三</van-tab>
|
||||||
@ -22,6 +22,15 @@ export default {
|
|||||||
return {
|
return {
|
||||||
active: 0
|
active: 0
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
handleTabClick(index) {
|
||||||
|
this.$emit('click');
|
||||||
|
},
|
||||||
|
handleTabDisabledClick(index) {
|
||||||
|
this.$emit('disabled');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -36,4 +36,36 @@ describe('Tabs', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('listen click event', (done) => {
|
||||||
|
wrapper = mount(TabsTestComponent, {
|
||||||
|
attachToDocument: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const clickSpy = sinon.spy();
|
||||||
|
wrapper.vm.$on('click', clickSpy);
|
||||||
|
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
const nTab = wrapper.find('.van-tab')[0];
|
||||||
|
nTab.simulate('click');
|
||||||
|
expect(clickSpy.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('listen click disable event', (done) => {
|
||||||
|
wrapper = mount(TabsTestComponent, {
|
||||||
|
attachToDocument: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const clickDisabledSpy = sinon.spy();
|
||||||
|
wrapper.vm.$on('disabled', clickDisabledSpy);
|
||||||
|
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
const nTab = wrapper.find('.van-tab')[2];
|
||||||
|
nTab.simulate('click');
|
||||||
|
expect(clickDisabledSpy.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user