index.vue 1.2 KB
Newer Older
P
Pan 已提交
1 2
<template>
  <div class="tab-container">
P
Pan 已提交
3
    <el-tag>mounted times :{{createdTimes}}</el-tag>
花裤衩 已提交
4 5
    <el-alert style="width:200px;display:inline-block;vertical-align: middle;margin-left:30px;" title="Tab with keep-alive" type="success" :closable="false">
    </el-alert>
P
Pan 已提交
6 7 8 9 10 11 12 13 14 15 16
    <el-tabs style='margin-top:15px;' v-model="activeName" type="border-card">
      <el-tab-pane v-for="item in tabMapOptions" :label="item.label" :key='item.key' :name="item.key">
        <keep-alive>
          <tab-pane v-if='activeName==item.key' :type='item.key' @create='showCreatedTimes'></tab-pane>
        </keep-alive>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
P
Pan 已提交
17
import tabPane from './components/tabPane'
P
Pan 已提交
18

P
Pan 已提交
19
export default {
20
  name: 'tab',
P
Pan 已提交
21 22 23 24
  components: { tabPane },
  data() {
    return {
      tabMapOptions: [
花裤衩 已提交
25 26 27 28
        { label: 'China', key: 'CN' },
        { label: 'USA', key: 'US' },
        { label: 'Japan', key: 'JP' },
        { label: 'Eurozone', key: 'EU' }
P
Pan 已提交
29 30 31 32 33 34 35 36
      ],
      activeName: 'CN',
      createdTimes: 0
    }
  },
  methods: {
    showCreatedTimes() {
      this.createdTimes = this.createdTimes + 1
P
Pan 已提交
37 38
    }
  }
P
Pan 已提交
39
}
P
Pan 已提交
40 41 42 43 44 45 46
</script>

<style scoped>
  .tab-container{
    margin: 30px;
  }
</style>