<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## tabs組件 在`src/layouts/TabsView.vue`新建多頁簽組件,找到官網`tabs`組件 ``` <template> <div> <div :style="{ marginBottom: '16px' }"> <a-button @click="add"> ADD </a-button> </div> <a-tabs v-model="activeKey" hide-add type="editable-card" @edit="onEdit"> <a-tab-pane v-for="pane in panes" :key="pane.key" :tab="pane.title" :closable="pane.closable"> {{ pane.content }} </a-tab-pane> </a-tabs> </div> </template> <script> export default { data() { const panes = [ { title: 'Tab 1', content: 'Content of Tab 1', key: '1' }, { title: 'Tab 2', content: 'Content of Tab 2', key: '2' }, ]; return { activeKey: panes[0].key, panes, newTabIndex: 0, }; }, methods: { callback(key) { console.log(key); }, onEdit(targetKey, action) { this[action](targetKey); }, add() { const panes = this.panes; const activeKey = `newTab${this.newTabIndex++}`; panes.push({ title: `New Tab ${activeKey}`, content: `Content of new Tab ${activeKey}`, key: activeKey, }); this.panes = panes; this.activeKey = activeKey; }, remove(targetKey) { let activeKey = this.activeKey; let lastIndex; this.panes.forEach((pane, i) => { if (pane.key === targetKey) { lastIndex = i - 1; } }); const panes = this.panes.filter(pane => pane.key !== targetKey); if (panes.length && activeKey === targetKey) { if (lastIndex >= 0) { activeKey = panes[lastIndex].key; } else { activeKey = panes[0].key; } } this.panes = panes; this.activeKey = activeKey; }, }, }; </script> ``` 去掉add功能,修改代碼 ``` <template> <a-tabs v-model="activePage" type="editable-card" :hide-add="true" @edit="editPage"> <!-- edit 新增和刪除頁簽的回調,在 type="editable-card" 時有效 --> <a-tab-pane v-for="page in pageList" :key="page.fullPath"> <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span> </a-tab-pane> </a-tabs> </template> <script> export default { data() { return { activePage: "", pageList: [], // 頁簽的路由數組 }; }, created() { const route = this.$route; this.pageList.push(route); this.activePage = route.fullPath; }, watch: { $route: function (newRoute) { // 當前路由高亮 this.activePage = newRoute.fullPath; // 當前路由在頁簽中不存在時添加新頁簽 if (this.pageList.findIndex(item => item.fullPath == newRoute.fullPath) == -1) { this.pageList.push(newRoute); } } }, methods: { callback(key) { console.log(key); }, editPage(key, action) { this[action](key); // remove }, remove(key, next) { // 頁簽只有一個時 不能關閉 if (this.pageList.length === 1) { return this.$message.warning("這是最后一頁,不能再關閉了"); } // 當前頁簽的索引 let index = this.pageList.findIndex(item => item.fullPath === key); // 刪除當前頁簽 this.pageList.splice(index, 1); if (next) { this.$router.push(next); } else if (key === this.activePage) { index = index >= this.pageList.length ? this.pageList.length - 1 : index; this.activePage = this.pageList[index].fullPath; this.$router.push(this.activePage); } }, } }; </script> ``` 在BasicLayout.vue中引入 ``` <a-layout-content style="margin: 0 16px"> <!-- <router-view></router-view> --> <tabs-view></tabs-view> </a-layout-content> ``` ## CustomEvent自定義頁簽關閉事件 用法 ``` // 添加一個適當的事件監聽器 obj.addEventListener("cat", function(e) { process(e.detail) }) // 創建并分發事件 var event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}}) obj.dispatchEvent(event) ``` 新建`src/plugins/tabs-page-plugin.js` ``` const TabsPagePlugin = { install(Vue) { Vue.mixin({ methods: { $closePage(closeRoute, nextRoute) { // CustomEvent() 創建一個自定義事件 // CustomEvent.detail 只讀 任何時間初始化時傳入的數據 const event = new CustomEvent("page:close", { detail: { closeRoute, nextRoute } }); window.dispatchEvent(event); } } }); } }; export default TabsPagePlugin; ``` 新建`src/plugins/index.js`,引入`TabsPagePlugin` ``` import TabsPagePlugin from "./tabs-page-plugin"; const Plugins = { install: function (Vue) { Vue.use(TabsPagePlugin); } }; export default Plugins; ``` `main.js`引入 ``` import Plugins from "@/plugins"; Vue.use(Plugins); ``` 修改`src/layouts/TabsView.vue` ``` <template> <a-tabs v-model="activePage" type="editable-card" :hide-add="true" @edit="editPage"> <!-- edit 新增和刪除頁簽的回調,在 type="editable-card" 時有效 --> <a-tab-pane v-for="page in pageList" :key="page.fullPath"> <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span> </a-tab-pane> </a-tabs> <div class="tabs-view-content"> <keep-alive> <router-view :key="$route.fullPath" ref="tabContent"/> </keep-alive> </div> </template> <script> export default { data() { return { activePage: "", pageList: [], // 頁簽的路由數組 }; }, created() { const route = this.$route; this.pageList.push(route); this.activePage = route.fullPath; // 自定義監聽關閉事件 window.addEventListener("page:close", this.closePageListener); }, beforeDestroy() { window.removeEventListener("page:close", this.closePageListener); }, watch: { $route: function (newRoute) { // 當前路由高亮 this.activePage = newRoute.fullPath; // 當前路由在頁簽中不存在時添加新頁簽 if (this.pageList.findIndex(item => item.fullPath == newRoute.fullPath) == -1) { this.pageList.push(newRoute); } } }, methods: { callback(key) { console.log(key); }, editPage(key, action) { this[action](key); // remove }, remove(key, next) { // 頁簽只有一個時 不能關閉 if (this.pageList.length === 1) { return this.$message.warning("這是最后一頁,不能再關閉了"); } // 當前頁簽的索引 let index = this.pageList.findIndex(item => item.fullPath === key); // 刪除當前頁簽 this.pageList.splice(index, 1); if (next) { this.$router.push(next); } else if (key === this.activePage) { index = index >= this.pageList.length ? this.pageList.length - 1 : index; this.activePage = this.pageList[index].fullPath; this.$router.push(this.activePage); } }, closePageListener(event) { const { closeRoute, nextRoute } = event.detail; const closePath = typeof closeRoute === "string" ? closeRoute : closeRoute.path; this.remove(closePath, nextRoute); } } }; </script> ``` ## 使用 關閉當前頁面:`this.$closePage(this.$route.fullPath);`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看