BootstrapVue選項(xiàng)卡標(biāo)題增加關(guān)閉按鈕的方法
BootstrapVue選項(xiàng)卡標(biāo)題增加關(guān)閉按鈕,供大家參考,具體內(nèi)容如下
BootstrapVue官網(wǎng)選項(xiàng)卡組件中,沒有列出選項(xiàng)卡標(biāo)題帶關(guān)閉按鈕的,這里參照官網(wǎng)的例子進(jìn)行修改,給標(biāo)題加上關(guān)閉按鈕。
官網(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>
利用插槽向選項(xiàng)卡標(biāo)題添加icon圖標(biāo),選關(guān)閉按鈕圖形,并綁定關(guān)閉事件。修改后代碼如下:
<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"> ? ? ? ? ? ? <!--用插槽想標(biāo)題添加icon圖標(biāo),同時將關(guān)閉按鈕調(diào)用的時間轉(zhuǎn)移到圖標(biāo)的點(diǎn)擊事件中執(zhí)行--> ? ? ? ? ? ? <template v-slot:title> ? ? ? ? ? ? ? ? ? ? Tab{{ i }} ? ? ? ? ? ? ? ? ? ? <!--插入icon圖標(biāo),關(guān)閉按鈕圖形--> ? ? ? ? ? ? ? ? ? ? <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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
bootstrap multiselect 多選功能實(shí)現(xiàn)方法
這篇文章主要介紹了bootstrap multiselect 多選功能實(shí)現(xiàn)方法,需要的朋友可以參考下2017-06-06JavaScript獲取圖片像素顏色并轉(zhuǎn)換為box-shadow顯示
這篇文章主要介紹了JavaScript獲取圖片像素顏色并轉(zhuǎn)換為box-shadow顯示的方法,用到了HTML5中的FileReader API和getImageData,轉(zhuǎn)換為的CSS3 box-shadow也要注意瀏覽器的兼容問題,需要的朋友可以參考下2016-03-03JS基于Ajax實(shí)現(xiàn)的網(wǎng)頁Loading效果代碼
這篇文章主要介紹了JS基于Ajax實(shí)現(xiàn)的網(wǎng)頁Loading效果代碼,通過時間函數(shù)結(jié)合數(shù)學(xué)運(yùn)算實(shí)現(xiàn)頁面樣式的動態(tài)變換技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10實(shí)例詳解JavaScript中setTimeout函數(shù)的執(zhí)行順序
關(guān)于javascript的運(yùn)行機(jī)制大家都應(yīng)該有所了解了吧,其實(shí)javascript是一個單線程的機(jī)制,但是因?yàn)殛?duì)列的關(guān)系它的表現(xiàn)會讓我們感覺是一個多線程的錯覺。下面這篇文章通過實(shí)例主要給大家介紹了關(guān)于JavaScript中setTimeout函數(shù)執(zhí)行順序的相關(guān)資料,需要的朋友可以參考下。2017-07-07