Skip to content

Commit a7060cc

Browse files
authored
Merge pull request #1 from alexqdjay/v0.2.0
V0.2.0
2 parents 212b860 + 20b1418 commit a7060cc

24 files changed

+800
-98
lines changed

build/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
banner: `/**
2626
* vue-tabs v${version}
2727
* (c) ${new Date().getFullYear()} ALEXQDJAY
28-
* @license MIT
28+
29+
* @license Apache2
2930
*/`
3031
}

docs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
1. [Installation](./installation.md)
44
1. [Getting Started](./start.md)
5+
1. [Config](./config.md)
56
1. [Guards](./guards.md)
6-
1. [API](./api.md)
7+
1. [API](./api.md)
8+
1. [Lazy Loading](./lazy_loading.md)
9+
10+
[Chinese Documentation (中文版文档)](./zh-cn/README.md)

docs/api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ Only **One VueTaber** exists in our system, it's `this.$taber` inside component
1212

1313
Open a Tab, if it has be existed it would be setted `ative`, it would be created.
1414

15+
`key` is a field of param, when the param is a object, and it is optional. The ID of tab equals it's name plus it's key, so if name is 'user' and key is '002', the ID would be 'user#002'.
16+
17+
If has the same name but key is different,that would create two tabs.
18+
1519
``` js
1620
this.$taber.open('home') // open the tab named 'home'
1721

1822
// or object
1923
this.$taber.open({
20-
name: 'home'
24+
name: 'home',
25+
key: user.id
2126
})
2227
```
2328

docs/config.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Config
2+
3+
The configuration of `vue-tabs` is so simple.
4+
5+
6+
## VueTaber config
7+
8+
``` js
9+
const vueTaber = new VueTaber({
10+
tabs: Array,
11+
persist: Boolean
12+
})
13+
14+
```
15+
16+
- **tabs**
17+
18+
A array contains tab configurations.
19+
20+
- **persist**
21+
22+
use localStorage to persist opened tabs, then these tabs would be restore when refresh
23+
browser.
24+
25+
26+
## Tab config
27+
28+
```js
29+
const tabs = [{
30+
name: 'user', // REQUIRED
31+
component: component // REQUIRED,
32+
title: 'title', // REQUIRED
33+
beforeCreate: createHook // [OPTIONAL],
34+
beforeClose: closeHook // [OPTIONAL]
35+
}]
36+
37+
```
38+
39+
- **name**
40+
41+
The ID of tab equals it's name plus it's key, so if name is 'user' and key is '002', the ID would be 'user#002'.
42+
43+
The name is used to get the configuration, and key is used to distinguish tabs which has the same name.
44+
45+
- **component**
46+
47+
The component will be created, when it's tab is opened.
48+
49+
- **title**
50+
51+
The title of tab.
52+
53+
- **beforeCreate, beforeClose**
54+
55+
hooks of `vue-tabs`, see [Guards](./guards.md)

docs/lazy_loading.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Lazy Loading
2+
3+
Because of some components‘ size is so big and rarely used, we can load these components when we open the tab which is mapped to the component.
4+
5+
Vue has the async component feature, but `vue-tabs` can't use it simply now, `vue-tabs` using Promise to achieve the target. Combining Webpack's code splitting feature, we can easy to lazy-load the compoent.
6+
7+
A basic example as follows:
8+
9+
```js
10+
11+
const Foo = resolve => {
12+
// require.ensure is Webpack's usage
13+
require.ensure(['./Foo.vue'], () => {
14+
resolve(require('./Foo.vue'))
15+
})
16+
}
17+
18+
// config of tab
19+
{
20+
name: 'async',
21+
title: '异步组件',
22+
component: Foo
23+
}
24+
```

docs/zh-cn/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 文档
2+
3+
1. [安装](./installation.md)
4+
1. [开始使用](./start.md)
5+
1. [配置](./config.md)
6+
1. [钩子](./guards.md)
7+
1. [API接口](./api.md)
8+
1. [懒加载](./lazy_loading.md)

docs/zh-cn/api.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# 接口
2+
3+
## VueTaber 实例
4+
5+
在系统中只会存在**一个 VueTaber**, 在组件中可以直接使用`this.$taber`来获取.
6+
7+
### 方法
8+
9+
- **taber.open(tab)**
10+
11+
- 参数类型: Object/String
12+
13+
调用时, 如果没有该的`ID`tab存在, 则新建一个tab, 否则激活该tab.
14+
15+
`key`是参数`param`的一个可选字段.
16+
17+
tab的`ID`的构成: name#key, 如name为`user`, key为`002`, 那么ID为`user#002`.
18+
19+
所以, 如果name一样, key不一样那么ID也会不一样, 这样会重新打开一个tab.
20+
21+
``` js
22+
this.$taber.open('home') // 打开一个`name`为home的tab
23+
24+
// 也可以传入对象
25+
this.$taber.open({
26+
name: 'home',
27+
key: user.id
28+
})
29+
```
30+
31+
32+
- **taber.close(tab)**
33+
34+
- **taber.select(tab)**
35+
36+
- **taber.$on(event, callback)**
37+
38+
- **taber.$off(event[, callback])**
39+
40+
- **taber.beforeCreateEach(hookFn)**
41+
42+
添加全局钩子
43+
44+
45+
- **taber.beforeCloseEach(hookFn)**
46+
47+
48+
## Tab Object
49+
50+
**tab 对象** 代表当前标签页的状态数据, 它还包含**标签的配置信息**
51+
52+
- **tab.name**
53+
- **tab.meta**
54+
55+
- 类型: Object
56+
57+
配置信息
58+
59+
60+
## 事件
61+
62+
- **`vue-tabs-active-change: function (tab)`**: 当激活另一个标签页时触发
63+
- **`ue-tabs-close: function (tab)`**: 当标签页被关闭时触发
64+
65+
66+
这两个事件的响应处理方法都会接受到`tab`这个参数
67+

docs/zh-cn/config.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 配置
2+
3+
`vue-tabs`的配置非常简单.
4+
5+
6+
## VueTaber 配置
7+
8+
``` js
9+
const vueTaber = new VueTaber({
10+
tabs: Array,
11+
persist: Boolean
12+
})
13+
14+
```
15+
16+
- **tabs**
17+
18+
包含`tab`配置的数组
19+
20+
- **persist**
21+
22+
配置是否需要用`localStorage`记录已经打开的标签, 这样如果刷新浏览器或者关闭打开浏览器还能恢复这些标签.
23+
24+
25+
## Tab 配置
26+
27+
```js
28+
const tabs = [{
29+
name: 'user', // 必需
30+
component: component // 必需,
31+
title: 'title', // 必需
32+
beforeCreate: createHook // [可选],
33+
beforeClose: closeHook // [可选]
34+
}]
35+
36+
```
37+
38+
- **name**
39+
40+
标签的ID由`name + # + key`生成, 由此来唯一确定一个标签.
41+
42+
`name`是用来获取标签的配置. 当两个标签的`name`相同时, 可以使用`key`是用来区分标签.
43+
44+
- **component**
45+
46+
配置的组件会在对应标签页打开时创建.
47+
48+
- **title**
49+
50+
标签上显示的标题.
51+
52+
- **beforeCreate, beforeClose**
53+
54+
配置钩子, 详细见[Guards](./guards.md)

docs/zh-cn/guards.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 钩子
2+
3+
`VueTaber`实例提供了用于响应标签创建和关闭的钩子函数注册.
4+
5+
目前有两种方式配置钩子函数: 全局配置的和每个标签页配置的.
6+
7+
### 全局配置
8+
9+
```js
10+
const taber = new VueTaber({...})
11+
taber.beforeCreateEach((tab, next) => {
12+
// ...
13+
})
14+
15+
taber.beforeCloseEach((tab, next) => {
16+
// ...
17+
})
18+
```
19+
20+
钩子是按创建顺序进行调用的, 先创建的先被调用.
21+
22+
每个钩子函数都接收到两个参数:
23+
24+
- **`tab: Object`**: 目标标签的数据对象 [标签数据对象](./api.md)
25+
26+
- **`next: Function`**: 这个方法必须被调用, 不然就会没有任何响应, 调用后下一步的动作依赖传入的参数
27+
28+
- **`next()`**: 进行下个钩子函数的执行
29+
30+
- **`next(false)`**: 放弃本次变化(创建或者关闭标签)
31+
32+
- **`next(target)`**: `target:Object/String`, 放弃本次变化, 转向其他目标`target`, **只对创建起作用, 关闭时不起作用**
33+
34+
35+
### 每个标签配置
36+
37+
```js
38+
const vueTaber = new VueTaber({
39+
tabs: [{
40+
name: 'home',
41+
title: '首页',
42+
component: Hello,
43+
beforeCreate (tab, next) {
44+
console.log('before create:', tab)
45+
next()
46+
},
47+
beforeClose (tab, next) {
48+
console.log('before close', tab)
49+
next()
50+
}
51+
}]
52+
})
53+
```
54+

docs/zh-cn/installation.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 安装
2+
3+
### 直接外联
4+
5+
在Html中引入, 它会自动安装
6+
7+
``` html
8+
<script src="/path/to/vue.js"></script>
9+
<script src="/path/to/vue-tabs.js"></script>
10+
```
11+
12+
### NPM安装
13+
14+
``` bash
15+
npm install vue-tabs
16+
```
17+
18+
如果你是模块化开发,那么你`require`或者`import`后需要通过调用`vue.use()`进行安装
19+
20+
``` js
21+
import Vue from 'vue'
22+
import VueTaber from 'vue-tabs'
23+
24+
Vue.use(VueTaber)
25+
26+
```
27+
28+
### 构建开发版
29+
30+
你也可以从github上直接使用最新的开发般,然后直接构建
31+
32+
``` bash
33+
git clone [email protected]:alexqdjay/vue-tabs.git node_modules/vue-tabs
34+
cd node_modules/vue-tabs
35+
npm install
36+
npm run build
37+
```

docs/zh-cn/lazy_loading.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 懒加载
2+
3+
介于有些组件比较大或者一般情况使用不到, 我们可以在打开那些对应的标签时再来加载这些组件.
4+
5+
vue本身就有异步组件的概念, 但`vue-tabs`暂时没能用到该机制, `vue-tabs`的异步组件是直接基于Promise去实现, 在实际开发中结合 webpack 的`code splitting feature`来实现懒加载是非常简单的事情.
6+
7+
下面是简单的示例:
8+
9+
```js
10+
11+
const Foo = resolve => {
12+
// require.ensure 是 Webpack 的特殊语法, 配置需要分块的文件
13+
require.ensure(['./Foo.vue'], () => {
14+
resolve(require('./Foo.vue'))
15+
})
16+
}
17+
18+
{
19+
name: 'async',
20+
title: '异步组件',
21+
component: Foo
22+
}
23+
```

0 commit comments

Comments
 (0)