element/packages/tabs/src/tab-pane.vue

65 lines
1.2 KiB
Vue
Raw Normal View History

2016-07-27 06:15:02 +00:00
<script>
module.exports = {
name: 'el-tab-pane',
props: {
label: {
type: String,
required: true
},
name: String
2016-07-27 06:15:02 +00:00
},
data() {
return {
counter: 0,
transition: '',
paneStyle: {
position: 'relative'
},
2016-11-04 03:28:23 +00:00
index: ''
2016-07-27 06:15:02 +00:00
};
},
created() {
2016-11-04 03:28:23 +00:00
if (!this.index) {
this.index = this.$parent.$children.indexOf(this) + 1 + '';
2016-07-27 06:15:02 +00:00
}
},
computed: {
show() {
2016-11-04 03:28:23 +00:00
return this.$parent.currentName === this.index;
2016-07-27 06:15:02 +00:00
}
},
2016-09-28 07:20:50 +00:00
destroyed() {
2016-11-04 09:07:49 +00:00
if (this.$el) {
2016-11-08 16:01:56 +00:00
this.$el.parentNode.removeChild(this.$el);
2016-11-04 09:07:49 +00:00
}
2016-09-28 07:20:50 +00:00
},
2016-07-27 06:15:02 +00:00
watch: {
name: {
immediate: true,
handler(val) {
2016-11-04 03:28:23 +00:00
this.index = val;
}
},
'$parent.currentName'(newValue, oldValue) {
2016-11-04 03:28:23 +00:00
if (this.index === newValue) {
2016-07-27 06:15:02 +00:00
this.transition = newValue > oldValue ? 'slideInRight' : 'slideInLeft';
}
2016-11-04 03:28:23 +00:00
if (this.index === oldValue) {
2016-07-27 06:15:02 +00:00
this.transition = oldValue > newValue ? 'slideInRight' : 'slideInLeft';
}
}
}
};
</script>
<template>
2016-09-30 11:44:46 +00:00
<div class="el-tab-pane" v-show="show && $slots.default">
2016-07-27 06:15:02 +00:00
<slot></slot>
</div>
</template>