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

60 lines
1.1 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'
},
key: ''
2016-07-27 06:15:02 +00:00
};
},
created() {
if (!this.key) {
this.key = this.$parent.$children.indexOf(this) + 1 + '';
}
},
computed: {
show() {
return this.$parent.currentName === this.key;
2016-07-27 06:15:02 +00:00
}
},
watch: {
name: {
immediate: true,
handler(val) {
this.key = val;
}
},
'$parent.currentName'(newValue, oldValue) {
2016-07-27 06:15:02 +00:00
if (this.key === newValue) {
this.transition = newValue > oldValue ? 'slideInRight' : 'slideInLeft';
}
if (this.key === oldValue) {
this.transition = oldValue > newValue ? 'slideInRight' : 'slideInLeft';
}
}
}
};
</script>
<template>
<div class="el-tab-pane" v-if="show && $slots.default">
2016-07-27 06:15:02 +00:00
<slot></slot>
</div>
</template>