<?php
$kn[0] = 'Home';
$cont[0] = 'Home component';
$kn[1] = 'Posts';
$cont[1] = 'Posts component';
$kn[2] = 'Archive';
$cont[2] = 'Archive component';
$kn[3] = 'ещё Таб1';
$cont[3] = 'my Таб первый';
$kn[4] = 'Таб n-ый';
$cont[4] = 'Количество Табов неограничено';
$taby = new Taby;
?>
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Components Example</title>
<script src="https://unpkg.com/vue"></script>
<style>
.tab-button {
padding: 6px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border: 1px solid #ccc;
cursor: pointer;
background: #f0f0f0;
margin-bottom: -1px;
margin-right: -1px;
}
.tab-button:hover {
background: #e0e0e0;
}
.tab-button.active {
background: #e0e0e0;
}
.tab {
border: 1px solid #ccc;
padding: 10px;
}
</style>
</head>
<body>
<?php $taby->display($kn, $cont)?>
<p>=========== ==================== ================= =================</p>
<div id="dynamic-component-demo" class="demo">
<button
v-for="tab in tabs"
v-bind:key="tab"
v-bind:class="['tab-button', { active: currentTab === tab }]"
v-on:click="currentTab = tab"
>
{{ tab }}
</button>
<component v-bind:is="currentTabComponent" class="tab"></component>
</div>
<script>
Vue.component("tab-home", {
template: "<div>Home component</div>"
});
Vue.component("tab-posts", {
template: "<div>Posts component</div>"
});
Vue.component("tab-archive", {
template: "<div>Archive component</div>"
});
new Vue({
el: "#dynamic-component-demo",
data: {
currentTab: "Home",
tabs: ["Home", "Posts", "Archive"]
},
computed: {
currentTabComponent: function() {
return "tab-" + this.currentTab.toLowerCase();
}
}
});
</script>
</body>
</html>
<?php
class taby{
function display($kn, $kont){
$kol_kn = count($kn);
for($i=0;$i<$kol_kn;++$i){
?>
<button id="kn<?=$i?>" class="tab-button<?php if($i==0) print ' active';?>"
onclick="otrTab(<?=$i?>,<?=$kol_kn?>)"><?=$kn[$i]?></button>
<?php
}
for($i=0;$i<$kol_kn;++$i){
?>
<div id="tab<?=$i?>" class="tab"<?php if($i!=0) print ' style="display:none"';?>><?=$kont[$i]?></div>
<?php
}?>
<script>
function otrTab(t, kol_kn){
let u = [];
let cv =[];
for(let i=0; i < kol_kn; i++){
u[i] = 'none';
u[t] = 'block';
cv[i] = '#f0f0f0';
cv[t] = '#e0e0e0';
globalThis['tab'+i].style.display = u[i];
globalThis['kn'+i].style.background = cv[i];
}
}
</script>
<?php
}
}