Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit da0d005

Browse files
author
Ken Berkeley
committed
docs/
1 parent 772acf5 commit da0d005

File tree

11 files changed

+174
-3
lines changed

11 files changed

+174
-3
lines changed

docs/LANGS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Languages
2+
3+
* [中文](zh-cn/)

docs/zh-cn/GettingStarted.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# § 开始
2+
3+
我们以 [`example/Basic/index.vue`](https://github.com/kenberkeley/vue2-datatable/blob/master/example/Basic/index.vue) 为例,效果见 [demo](https://kenberkeley.github.io/vue2-datatable/example-dist)
4+
5+
```html
6+
<template>
7+
<div>
8+
<code>query: {{ query }}</code>
9+
<datatable v-bind="$data" />
10+
</div>
11+
</template>
12+
<script>
13+
import Datatable from 'vue2-datatable'
14+
import mockData from '../_mockData'
15+
16+
export default {
17+
components: { Datatable },
18+
data: () => ({
19+
columns: [
20+
{ title: 'User ID', field: 'uid', sort: true },
21+
{ title: 'Username', field: 'name' },
22+
{ title: 'Age', field: 'age', sort: true },
23+
{ title: 'Email', field: 'email' },
24+
{ title: 'Country', field: 'country' }
25+
],
26+
data: [],
27+
total: 0,
28+
query: {}
29+
}),
30+
watch: {
31+
query: {
32+
handler (query) {
33+
mockData(query).then(({ rows, total }) => {
34+
this.data = rows
35+
this.total = total
36+
})
37+
},
38+
deep: true
39+
}
40+
}
41+
}
42+
</script>
43+
```

docs/zh-cn/Preface.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# § 前言
2+
3+
> 本 Datatable 仅支持 Vue 2.x
4+
5+
任何开源的 Datatable 都未必能满足所有的业务需求(否则也不会有这个项目了)
6+
本文档致力于让您在理解组件设计以及源码的基础上,可自行定制出最适合的 Datatable
7+
8+
本 Datatable 的依赖如下:
9+
10+
* BootStrap 3.x + Font Awesome 4.x(全局引入)
11+
* [lodash.orderBy](https://lodash.com/docs/4.17.4#orderBy)
12+
* [replace-with](https://github.com/kenberkeley/replace-with)
13+
14+
注:BootStrap 以及 Font Awesome 的可替换性极强,您完全可以使用其他库替代(一般就是改一下类名即可)

docs/zh-cn/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "./SUMMARY.md" %}

docs/zh-cn/SUMMARY.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# § 总览
2+
3+
* [总览](README.md)
4+
* [前言](Preface.md)
5+
* [源码技巧](Tricks.md)
6+
* [开始](GettingStarted.md)
7+
* [深入了解](development/README.md)
8+
* [谈状态管理](development/State-management.md)
9+
* [URL 是单页应用的精华](development/URL-is-soul-of-SPA.md)
10+
* [引入服务层](development/Service-layer.md)
11+
* [Ajax 接口化](development/Ajax-interface.md)
12+
* [配置](development/Configuration.md)
13+
* [跨域与代理](development/CORS-and-Proxy.md)
14+
* [最佳实践](development/Best-practice.md)
15+
* [问题反馈(issues)](https://github.com/kenberkeley/vue2-datatable/issues)
16+
* [版本迭代(releases)](https://github.com/kenberkeley/vue2-datatable/releases)

docs/zh-cn/Tricks.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# § 源码技巧
2+
3+
> 在开始前,最好先来做一下预备功课
4+
5+
***
6+
7+
#### ⊙ 了解动态组件的用法
8+
详情请参考文档:[Dynamic Components](https://vuejs.org/v2/guide/components.html#Dynamic-Components)
9+
10+
#### ⊙ 巧用 [`v-bind`](https://cn.vuejs.org/v2/api/#v-bind) 实现类似 JSX 中的 spread operator (`...`)
11+
> 本技巧参考自 [vuejs/vue#4962](https://github.com/vuejs/vue/issues/4962)
12+
13+
```html
14+
<template>
15+
<div>
16+
17+
<hello-world
18+
:a="a"
19+
:b="b"
20+
:c="c"
21+
:d="d">
22+
</hello-world>
23+
24+
<!-- 两种写法作用一致,但显然后者更优雅简洁 -->
25+
26+
<hello-world v-bind="$data" />
27+
28+
</div>
29+
</template>
30+
<script>
31+
export default {
32+
data: () => ({
33+
a: 1,
34+
b: 2,
35+
c: 3,
36+
d: 4
37+
})
38+
}
39+
</script>
40+
```
41+
42+
#### `propType: Boolean` 的模板简写
43+
44+
`HelloWorld` 组件中定义:
45+
46+
```js
47+
props: {
48+
test: Boolean
49+
}
50+
```
51+
52+
那么下面两种写法是等价的,但显然后者更优雅简洁
53+
54+
```html
55+
<hello-world
56+
:test="true">
57+
</hello-world>
58+
59+
<hello-world test />
60+
```
61+
62+
#### ⊙ 巧用逗号运算符
63+
64+
```js
65+
cols.map(col => {
66+
if (!col.weight) col.weight = 0
67+
return col
68+
})
69+
70+
// 利用逗号运算符,可以把上面的代码缩写为一行:
71+
cols.map(col => ((col.weight = col.weight || 0), col))
72+
```

example-dist/client.b5d31013.js

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

example-dist/client.ed009e18.css

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

example-dist/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Vue 2 Datatable Examples</title>
6+
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
7+
<link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
8+
<link href="client.ed009e18.css" rel="stylesheet"></head>
9+
<body>
10+
11+
<div id="app"></div>
12+
13+
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
14+
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
15+
<script type="text/javascript" src="client.b5d31013.js"></script></body>
16+
</html>

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "lib/index.vue",
77
"scripts": {
88
"start": "vue build example/App.vue --config vue-build.config.js",
9-
"build": "vue build example/App.vue --prod --config vue-build.config.js"
9+
"build": "vue build example/App.vue --prod --config vue-build.config.js",
10+
"build:docs": "gitbook build docs/"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -24,6 +25,7 @@
2425
"devDependencies": {
2526
"clean-webpack-plugin": "^0.1.16",
2627
"es6-shim": "^0.35.3",
28+
"gitbook-cli": "^2.3.0",
2729
"mockjs": "^1.0.1-beta3",
2830
"moment": "^2.18.1",
2931
"vue-cli": "^2.8.2"

0 commit comments

Comments
 (0)