vuejs2.0 組件基礎(chǔ)動(dòng)態(tài)組件 Tab選項(xiàng)卡插件

<!DOCTYPE?html>

<html?lang="en">

??<head>

????<meta?charset="UTF-8"?/>

????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0"?/>

????<meta?http-equiv="X-UA-Compatible"?content="ie=edge"?/>

????<title>Document</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>

????<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>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 下載安裝搭建環(huán)境 可以選npm安裝,或者簡(jiǎn)單下載一個(gè)開(kāi)發(fā)版的vue.js文件 瀏覽器打開(kāi)加載有vue的文檔時(shí),控制...
    冥冥2017閱讀 6,197評(píng)論 0 42
  • Vue 實(shí)例 屬性和方法 每個(gè) Vue 實(shí)例都會(huì)代理其 data 對(duì)象里所有的屬性:var data = { a:...
    云之外閱讀 2,369評(píng)論 0 6
  • 基于Vue的一些資料 內(nèi)容 UI組件 開(kāi)發(fā)框架 實(shí)用庫(kù) 服務(wù)端 輔助工具 應(yīng)用實(shí)例 Demo示例 element★...
    嘗了又嘗閱讀 1,282評(píng)論 0 1
  • 第一節(jié) vue:讀音: v-u-eview vue和angular區(qū)別?vue——簡(jiǎn)單、易學(xué)指令以 v-xxx一片...
    黑色的五葉草閱讀 1,194評(píng)論 0 1
  • 基本格式 以json的形式、將數(shù)據(jù)(支持所有格式)掛載在vue的data上、方法掛載在vue的methods上。 ...
    kirito_song閱讀 908評(píng)論 0 21

友情鏈接更多精彩內(nèi)容