完整源碼bash
<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> 複製代碼
小結app
1.獲取當前點擊的是哪一個button,經過el-radio-group的v-model=」radio」來獲得。radio在點擊後,值會是label=」代碼倉庫」其中的一個。 2.component經過v-bind動態傳值,進而達到切換tab內容的目的。