Skip to content

Commit 14f5a99

Browse files
authored
Merge pull request #2 from daylenjeez/feature-0.2.0-PartialRefactoring
# Vue3-Tabor v0.2.0 ## ⚠️ BREAKING CHANGES 1. API Method Change: `useRouterTab(router)` replaces `useTabor()`. The new method no longer requires parameters 2. CSS Class Prefix Change: Class name prefix changed from `rt-` to `tabor-`. Custom styles need to be updated ## 🔄 Migration Guide 1. Replace all `useRouterTab()` calls with `useTabor()` 2. Update any custom CSS styles using the `rt-` prefix to use the `tabor-` prefix
2 parents 0558d9c + 0f9a3e7 commit 14f5a99

36 files changed

+402
-446
lines changed

README.en.md

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ app.mount("#app");
9494
When installing the plugin, you can pass the following configuration options:
9595

9696
```js
97-
app.use(RouterTab, {
97+
app.use(Tabor, {
9898
router: router, // Required: Vue Router instance
9999
maxCache: 10, // Optional: Maximum cache size, default is 10
100100
});
@@ -117,6 +117,18 @@ The `<vue-tabor>` component supports the following properties:
117117
| tabPrefix | Component | - | Tab prefix component |
118118
| language | String | 'zh' | UI language, options: 'zh', 'en' |
119119

120+
### Internationalization
121+
122+
vue3-tabor supports both Chinese and English languages, which can be configured as follows:
123+
124+
```html
125+
<!-- Set to English -->
126+
<vue-tabor language="en" />
127+
128+
<!-- Set to Chinese -->
129+
<vue-tabor language="zh" />
130+
```
131+
120132
### Style Variables
121133

122134
vue3-tabor provides CSS variables that can be customized through the style prop or global CSS. Below are the available style variables:
@@ -222,12 +234,12 @@ For deeper customization needs, you can use the following methods:
222234
1. **Add custom styles using provided class names**:
223235
```css
224236
/* Custom tab styles */
225-
.rt-tabs .tab {
237+
.tabor-tab {
226238
/* Custom styles */
227239
}
228240

229241
/* Custom active tab styles */
230-
.rt-tabs .tab.active {
242+
.tabor-tab-active {
231243
/* Custom styles */
232244
}
233245
```
@@ -239,18 +251,18 @@ For deeper customization needs, you can use the following methods:
239251

240252
### Instance Methods
241253

242-
You can access the following methods through the injected `tabStore`:
254+
You can access the following methods through the `useTabor` hook:
243255

244256
```js
245257
// In your component
246-
import { inject } from 'vue';
258+
import { useTabor } from 'vue3-tabor'
247259

248260
export default {
249261
setup() {
250-
const tabStore = inject('tabStore');
262+
const tabor = useTabor();
251263

252-
// Use tabStore methods
253-
return { tabStore };
264+
// Use tabor methods
265+
return { tabor };
254266
}
255267
}
256268
```
@@ -321,33 +333,6 @@ tabStore.open({
321333
});
322334
```
323335

324-
### Internationalization
325-
326-
vue3-tabor supports both Chinese and English languages, which can be configured as follows:
327-
328-
```html
329-
<!-- Set to English -->
330-
<vue-tabor language="en" />
331-
332-
<!-- Set to Chinese -->
333-
<vue-tabor language="zh" />
334-
335-
<!-- Hide language switch button -->
336-
<vue-tabor :showLanguageSwitch="false" />
337-
```
338-
339-
You can also dynamically change the language using the API:
340-
341-
```js
342-
import { setLanguage } from 'vue3-tabor/utils/i18n';
343-
344-
// Switch to English
345-
setLanguage('en');
346-
347-
// Switch to Chinese
348-
setLanguage('zh');
349-
```
350-
351336
## 🔧 Tech Stack
352337

353338
- **💻 Vue 3**: Developed with the latest Vue 3.x version

README.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ app.mount("#app");
9494
在安装插件时,可以传入以下配置选项:
9595

9696
```js
97-
app.use(RouterTab, {
97+
app.use(Tabor, {
9898
router: router, // 必需:Vue Router 实例
9999
maxCache: 10, // 可选:最大缓存数量,默认为10
100100
});
@@ -129,18 +129,6 @@ vue3-tabor 支持中文和英文两种语言,可以通过以下方式进行配
129129
<vue-tabor language="zh" />
130130
```
131131

132-
你还可以通过 API 动态切换语言:
133-
134-
```js
135-
import { setLanguage } from 'vue3-tabor/utils/i18n';
136-
137-
// 切换为英文
138-
setLanguage('en');
139-
140-
// 切换为中文
141-
setLanguage('zh');
142-
```
143-
144132
### 样式变量
145133

146134
vue3-tabor 提供了以下 CSS 变量,可以通过 style 属性或全局 CSS 自定义主题样式:
@@ -246,12 +234,12 @@ vue3-tabor 提供了以下 CSS 变量,可以通过 style 属性或全局 CSS
246234
1. **使用提供的类名添加自定义样式**
247235
```css
248236
/* 自定义标签样式 */
249-
.rt-tabs .tab {
237+
.tabor-tab {
250238
/* 自定义样式 */
251239
}
252240

253241
/* 自定义激活标签样式 */
254-
.rt-tabs .tab.active {
242+
.tabor-tab-active {
255243
/* 自定义样式 */
256244
}
257245
```
@@ -267,14 +255,14 @@ vue3-tabor 提供了以下 CSS 变量,可以通过 style 属性或全局 CSS
267255

268256
```js
269257
// 在组件中使用
270-
import { inject } from 'vue';
258+
import { useTabor } from 'vue3-tabor'
271259

272260
export default {
273261
setup() {
274-
const tabStore = inject('tabStore');
262+
const tabor = useTabor();
275263

276-
// 使用tabStore方法
277-
return { tabStore };
264+
// 使用tabor方法
265+
return { tabor };
278266
}
279267
}
280268
```

examples/package-lock.json

Lines changed: 4 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"@vue/tsconfig": "^0.7.0",
1818
"typescript": "~5.7.2",
1919
"vite": "^6.2.0",
20-
"vue-tsc": "^2.2.4",
21-
"vue3-tabor": "^0.1.12"
20+
"vue-tsc": "^2.2.4"
2221
}
2322
}

examples/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import App from './App.vue'
44
import router from './router/index'
55
import Tabor from 'vue3-tabor'
66

7-
import 'vue3-tabor/dist/assets/index.css'
7+
import '../../dist/assets/index.css'
88

99
const app = createApp(App)
1010
app.use(router)

examples/src/router/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ const router = createRouter({
1818
path: '/path',
1919
name: 'key_is_path',
2020
component: () => import('../views/Path.vue'),
21-
meta:{
22-
tabConfig:{
21+
meta: {
22+
tabConfig: {
2323
key: 'path'
2424
} satisfies TabConfig
2525
}
2626
},
2727
{
2828
path: '/full-path',
2929
name: 'full_path',
30-
component: () => import('../views/fullPath.vue'),
31-
meta:{
32-
tabConfig:{
30+
component: () => import('../views/FullPath.vue'),
31+
meta: {
32+
tabConfig: {
3333
key: 'fullPath',
34-
name: (route:RouteLocationNormalized) => route.query.name as string
34+
name: (route: RouteLocationNormalized) => route.query.name as string
3535
} satisfies TabConfig
3636
}
3737
}

examples/src/views/Home.vue

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
<script setup lang="ts">
2-
import { useRouter } from 'vue-router'
3-
import { useTabStore } from 'vue3-tabor'
2+
import { useTabor } from 'vue3-tabor'
3+
const tabor = useTabor()
44
5-
const router = useRouter()
6-
const tabor = useTabStore(router)
75
86
const goToPath = () => {
97
tabor.open({
108
path: '/path',
11-
query: {
12-
name: 'tom'
13-
},
14-
})
9+
});
1510
}
1611
1712
const goToFullPath = (name: string) => {
18-
router.push({
13+
tabor.open({
1914
path: '/full-path',
20-
query: {
21-
name
22-
},
23-
})
15+
query: { name }
16+
});
2417
}
2518
</script>
2619

@@ -47,7 +40,7 @@ h1 {
4740
margin-bottom: 20px;
4841
}
4942
50-
button{
43+
button {
5144
margin-right: 10px;
5245
}
5346
</style>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-tabor",
3-
"version": "0.1.13",
3+
"version": "0.2.0",
44
"description": "Vue 3 routing tabs with keepAlive support, browser-like tab navigation for Vue applications",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.es.js",

src/components/page/iframe/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import type { RouterTabStore } from "@tabor/store";
1+
import { TABOR_STORE_KEY, type TaborStore } from "@tabor/store";
22
import {
33
computed,
44
defineComponent,
55
inject,
66
} from "vue";
77

88
export default defineComponent({
9-
name: "RtIframe",
9+
name: "Iframe",
1010

1111
setup() {
12-
const tabStore = inject<RouterTabStore>("tabStore");
12+
const taborStore = inject<TaborStore>(TABOR_STORE_KEY);
1313

14-
const iframes = computed(() => tabStore?.iframeTabs.value);
15-
//TODO: 需要考虑iframe刷新
14+
const iframes = computed(() => taborStore?.iframeTabs.value);
1615

1716
return () => (
18-
<div class="rt-iframe-container">
17+
<div class="tabor-iframe-container">
1918
{iframes.value?.map((iframe) => {
20-
const activeTabId = tabStore?.state.activeTab?.id;
21-
// 条件 1:是否需要保留组件 (活跃 或 keepAlive)
19+
const activeTabId = taborStore?.state.activeTab?.id;
2220
const shouldKeep = iframe.id === activeTabId || iframe.keepAlive;
2321

24-
// 条件 2:是否当前活跃需要显示
2522
const shouldShow = iframe.id === activeTabId;
2623

2724
return shouldKeep ? (

src/components/page/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.rt-pages {
1+
.tabor-pages {
22
padding: var(--page-padding);
33
}

0 commit comments

Comments
 (0)