BootstrapVue選項卡標題增加關閉按鈕的方法
BootstrapVue選項卡標題增加關閉按鈕,供大家參考,具體內容如下
BootstrapVue官網(wǎng)選項卡組件中,沒有列出選項卡標題帶關閉按鈕的,這里參照官網(wǎng)的例子進行修改,給標題加上關閉按鈕。
官網(wǎng)舉例:
<template> ? <div> ? ? <b-card no-body> ? ? ? <b-tabs card> ? ? ? ? <!-- Render Tabs, supply a unique `key` to each tab --> ? ? ? ? <b-tab v-for="i in tabs" :key="'dyn-tab-' + i" :title="'Tab ' + i"> ? ? ? ? ? Tab contents {{ i }} ? ? ? ? ? <b-button size="sm" variant="danger" class="float-right" @click="closeTab(i)"> ? ? ? ? ? ? Close tab ? ? ? ? ? </b-button> ? ? ? ? </b-tab> ? ? ? ? <!-- New Tab Button (Using tabs-end slot) --> ? ? ? ? <template v-slot:tabs-end> ? ? ? ? ? <b-nav-item @click.prevent="newTab" href="#" ><b>+</b></b-nav-item> ? ? ? ? </template> ? ? ? ? <!-- Render this if no tabs --> ? ? ? ? <template v-slot:empty> ? ? ? ? ? <div class="text-center text-muted"> ? ? ? ? ? ? There are no open tabs<br> ? ? ? ? ? ? Open a new tab using the <b>+</b> button above. ? ? ? ? ? </div> ? ? ? ? </template> ? ? ? </b-tabs> ? ? </b-card> ? </div> </template> <script> ? export default { ? ? data() { ? ? ? return { ? ? ? ? tabs: [], ? ? ? ? tabCounter: 0 ? ? ? } ? ? }, ? ? methods: { ? ? ? closeTab(x) { ? ? ? ? for (let i = 0; i < this.tabs.length; i++) { ? ? ? ? ? if (this.tabs[i] === x) { ? ? ? ? ? ? this.tabs.splice(i, 1) ? ? ? ? ? } ? ? ? ? } ? ? ? }, ? ? ? newTab() { ? ? ? ? this.tabs.push(this.tabCounter++) ? ? ? } ? ? } ? } </script>
利用插槽向選項卡標題添加icon圖標,選關閉按鈕圖形,并綁定關閉事件。修改后代碼如下:
<template> ? <div> ? ? <div> ? ? ? ? ? <b-nav-item @click.prevent="newTab" href="#" ><b>添加Tab頁</b></b-nav-item> ? ? </div> ? ? <div> ? ? ? <b-card no-body> ? ? ? ? <b-tabs card> ? ? ? ? ? <!-- Render Tabs, supply a unique `key` to each tab --> ? ? ? ? ? <b-tab v-for="i in tabs" :key="'dyn-tab-' + i"> ? ? ? ? ? ? <!--用插槽想標題添加icon圖標,同時將關閉按鈕調用的時間轉移到圖標的點擊事件中執(zhí)行--> ? ? ? ? ? ? <template v-slot:title> ? ? ? ? ? ? ? ? ? ? Tab{{ i }} ? ? ? ? ? ? ? ? ? ? <!--插入icon圖標,關閉按鈕圖形--> ? ? ? ? ? ? ? ? ? ? <a @click="closeTab(i)"> ? ? ? ? ? ? ? ? ? ? ? ? <b-icon icon="x-square"></b-icon> ? ? ? ? ? ? ? ? ? ? </a> ? ? ? ? ? ? </template> ? ? ? ? ? ? <h1> Tab-{{i}} </h1> ? ? ? ? ? </b-tab> ? ? ? ? ? <!-- New Tab Button (Using tabs-end slot) --> ? ? ? ? ? <!-- Render this if no tabs --> ? ? ? ? ? <template v-slot:empty> ? ? ? ? ? ? <div class="text-center text-muted"> ? ? ? ? ? ? ? There are no open tabs<br> ? ? ? ? ? ? ? Open a new tab using the <b>+</b> button above. ? ? ? ? ? ? </div> ? ? ? ? ? </template> ? ? ? ? </b-tabs> ? ? ? </b-card> ? ? </div> ? </div> </template> <script> export default { ? data () { ? ? return { ? ? ? tabs: [], ? ? ? tabCounter: 0 ? ? } ? }, ? methods: { ? ? closeTab (x) { ? ? ? for (let i = 0; i < this.tabs.length; i++) { ? ? ? ? if (this.tabs[i] === x) { ? ? ? ? ? this.tabs.splice(i, 1) ? ? ? ? } ? ? ? } ? ? }, ? ? newTab () { ? ? ? this.tabs.push(this.tabCounter++) ? ? } ? } } </script>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
bootstrap multiselect 多選功能實現(xiàn)方法
這篇文章主要介紹了bootstrap multiselect 多選功能實現(xiàn)方法,需要的朋友可以參考下2017-06-06JavaScript獲取圖片像素顏色并轉換為box-shadow顯示
這篇文章主要介紹了JavaScript獲取圖片像素顏色并轉換為box-shadow顯示的方法,用到了HTML5中的FileReader API和getImageData,轉換為的CSS3 box-shadow也要注意瀏覽器的兼容問題,需要的朋友可以參考下2016-03-03JS基于Ajax實現(xiàn)的網(wǎng)頁Loading效果代碼
這篇文章主要介紹了JS基于Ajax實現(xiàn)的網(wǎng)頁Loading效果代碼,通過時間函數(shù)結合數(shù)學運算實現(xiàn)頁面樣式的動態(tài)變換技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10實例詳解JavaScript中setTimeout函數(shù)的執(zhí)行順序
關于javascript的運行機制大家都應該有所了解了吧,其實javascript是一個單線程的機制,但是因為隊列的關系它的表現(xiàn)會讓我們感覺是一個多線程的錯覺。下面這篇文章通過實例主要給大家介紹了關于JavaScript中setTimeout函數(shù)執(zhí)行順序的相關資料,需要的朋友可以參考下。2017-07-07