效果图
完整源码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60<template>
<div id="app">
<div style="margin:0 auto;width:325px; margin-bottom:18px">
<el-radio-group v-model="radio" size="medium">
<el-radio-button label="代码仓库"></el-radio-button>
<el-radio-button label="网站"></el-radio-button>
<el-radio-button label="微博"></el-radio-button>
<el-radio-button label="公众号" disabled></el-radio-button>
</el-radio-group>
</div>
<!-- tab内容 -->
<keep-alive>
<component v-bind:is="tabView, tabChange(radio)" style="background: #FF0000; width: 100%; height: 100%"></component>
</keep-alive>
</div>
</template>
<script>
import select1 from './components/xxx1.vue';
import select2 from './components/xxx2.vue';
import select3 from './components/xxx3.vue';
import select4 from './components/xxx4.vue';
export default {
name: 'app',
data () {
return {
radio: '代码仓库',
tabView: 'select1',
}
},
components: {
select1,
select2,
select3,
select4
},
methods: {
tabChange(tab){
// this.tabView = tab;
console.log("tab:"+tab)
if('代码仓库' == tab){
this.tabView = 'select1'
}else if('网站' == tab){
this.tabView = 'select2'
}else if('微博' == tab){
this.tabView = 'select3'
}else if('公众号' == tab){
this.tabView = 'select4'
}
}
},
}
</script>
小结
1.获取当前点击的是哪个button,通过el-radio-group的v-model=”radio”来得到。radio在点击后,值会是label=”代码仓库”其中的一个。
2.component通过v-bind动态传值,进而达到切换tab内容的目的。