BootstrapVue選項卡標題增加關閉按鈕的方法
更新時間:2022年04月01日 10:21:09 作者:titan80001
這篇文章主要為大家詳細介紹了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>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Javascript實現(xiàn)顏色rgb與16進制轉換的方法
這篇文章主要介紹了Javascript實現(xiàn)顏色rgb與16進制轉換的方法,實例分析了顏色值轉換的常用技巧與使用方法,非常具有實用價值,需要的朋友可以參考下2015-04-04

