Merge pull request #92 from eleme/feat/fixed-tab

fixed tab bug
pull/2/head
baiyaaaaa 2016-08-22 18:58:09 +08:00 committed by GitHub
commit c927dfb1da
2 changed files with 11 additions and 14 deletions

View File

@ -23,8 +23,8 @@
handleRemove(tab) { handleRemove(tab) {
console.log(tab); console.log(tab);
}, },
handleClick(tab) { handleClick(tab, event) {
console.log(tab); console.log(tab, event);
} }
} }
} }
@ -38,7 +38,7 @@
## 基础使用 ## 基础使用
<div> <div>
<el-tabs :active-name="activeName"> <el-tabs>
<el-tab-pane label="选项卡一">选项卡一内容</el-tab-pane> <el-tab-pane label="选项卡一">选项卡一内容</el-tab-pane>
<el-tab-pane label="选项卡二">选项卡二内容</el-tab-pane> <el-tab-pane label="选项卡二">选项卡二内容</el-tab-pane>
<el-tab-pane label="选项卡三">选项卡三内容</el-tab-pane> <el-tab-pane label="选项卡三">选项卡三内容</el-tab-pane>
@ -121,10 +121,9 @@
|---------- |-------- |---------- |------------- |-------- | |---------- |-------- |---------- |------------- |-------- |
| type | 风格类型 | string | card, border-card | | | type | 风格类型 | string | card, border-card | |
| closable | 真实值 | boolean | true, false | false | | closable | 真实值 | boolean | true, false | false |
| defaultActiveName | 如果没有设置 activeName, 则使用该值 | string | | 第一个面板 |
| activeName | 当前选中面板的 name | string | | | | activeName | 当前选中面板的 name | string | | |
| tab.click | tab 被点击的回调 | string | | | | on-click | tab 被点击的钩子 | string | | |
| tab.remove | tab 被删除的回调 | string | | | | on-remove | tab 被删除的钩子 | string | | |
## TAB-PANE API ## TAB-PANE API
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | 参数 | 说明 | 类型 | 可选值 | 默认值 |

View File

@ -13,7 +13,6 @@
props: { props: {
type: String, type: String,
tabPosition: String, tabPosition: String,
defaultActiveName: String,
activeName: String, activeName: String,
closable: false, closable: false,
onRemove: { onRemove: {
@ -39,9 +38,8 @@
watch: { watch: {
activeName: { activeName: {
immediate: true,
handler(val) { handler(val) {
this.currentName = val || 0; this.currentName = val || this.$children[0].key;
} }
}, },
@ -70,12 +68,12 @@
} }
this.onRemove(tab.key); this.onRemove(tab.key);
}, },
handleTabClick(tab) { handleTabClick(tab, event) {
this.currentName = tab.key; this.currentName = tab.key;
this.onClick(tab.key); this.onClick(tab.key, event);
}, },
calcBarStyle() { calcBarStyle() {
if (this.type) return {}; if (this.type || !this.$refs.tabs) return {};
var style = {}; var style = {};
var offset = 0; var offset = 0;
var tabWidth = 0; var tabWidth = 0;
@ -100,7 +98,7 @@
mounted() { mounted() {
if (!this.currentName) { if (!this.currentName) {
this.currentName = this.defaultActiveName || this.$children[0].key; this.currentName = this.$children[0].key;
} }
this.$children.forEach(tab => this.tabs.push(tab)); this.$children.forEach(tab => this.tabs.push(tab));
this.$nextTick(() => this.calcBarStyle()); this.$nextTick(() => this.calcBarStyle());
@ -117,7 +115,7 @@
:tab="tab" :tab="tab"
:closable="closable" :closable="closable"
@remove="handleTabRemove" @remove="handleTabRemove"
@click.native="handleTabClick(tab)"> @click.native="handleTabClick(tab, $event)">
</el-tab> </el-tab>
<div <div
class="el-tabs__active-bar" class="el-tabs__active-bar"