Skip to content

Commit c086257

Browse files
committed
feat: support local registration & update README
1 parent 7de1898 commit c086257

File tree

3 files changed

+140
-25
lines changed

3 files changed

+140
-25
lines changed

README-zh.md

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ pnpm add @vue/composition-api
5858

5959
### Vue3
6060

61+
#### 单独引入
62+
> 推荐使用,因为对 tree-shaking 有更好的支持。
63+
```vue
64+
<script setup>
65+
import { CodeDiff } from 'v-code-diff'
66+
</script>
67+
68+
<template>
69+
<div>
70+
<CodeDiff
71+
old-string="12345"
72+
new-string="3456"
73+
output-format="side-by-side"
74+
/>
75+
</div>
76+
</template>
77+
```
78+
6179
#### 注册为全局组件
6280

6381
```ts
@@ -79,25 +97,38 @@ app.use(CodeDiff).mount('#app')
7997
</template>
8098
```
8199

82-
#### 单独引入
83-
84-
不推荐,但保留相关能力,方便 0.x 用户迁移
85-
86100
### Vue2
87101

88-
#### 注册为全局组件
102+
#### 单独引入
103+
> 推荐使用,因为对 tree-shaking 有更好的支持。
104+
```vue
105+
<script>
106+
import { CodeDiff } from 'v-code-diff'
107+
export default {
108+
components: {
109+
CodeDiff
110+
}
111+
}
112+
</script>
89113
114+
<template>
115+
<div>
116+
<CodeDiff
117+
old-string="12345"
118+
new-string="3456"
119+
output-format="side-by-side"
120+
/>
121+
</div>
122+
</template>
123+
```
124+
#### 注册为全局组件
90125
```ts
91126
import Vue from 'vue'
92127
import CodeDiff from 'v-code-diff'
93128

94129
Vue.use(CodeDiff)
95130
```
96131

97-
#### 单独引入
98-
99-
不推荐,但保留相关能力,方便 0.x 用户迁移
100-
101132
## Demo
102133

103134
| | npm | cdn |
@@ -157,13 +188,39 @@ Vue.use(CodeDiff)
157188
```shell
158189
pnpm add highlight.js
159190
```
191+
#### 单独引入
192+
> 推荐使用,因为对 tree-shaking 有更好的支持。
193+
```vue
194+
<script>
195+
import { CodeDiff, hljs } from 'v-code-diff'
196+
import c from 'highlight.js/lib/languages/c'
197+
// Extend C language
198+
hljs.registerLanguage('c', c)
199+
export default {
200+
components: {
201+
CodeDiff,
202+
}
203+
}
204+
</script>
160205
206+
<template>
207+
<div>
208+
<CodeDiff
209+
old-string="#include <stdio.h>"
210+
new-string="#include <stdio.h>\nint a = 1;"
211+
output-format="side-by-side"
212+
language="c"
213+
/>
214+
</div>
215+
</template>
216+
```
217+
#### 全局注册
161218
```typescript
162-
import CodeDiff from "v-code-diff";
219+
import CodeDiff from "v-code-diff"
163220
// Extend C language
164-
import c from "highlight.js/lib/languages/c";
221+
import c from "highlight.js/lib/languages/c"
165222

166-
CodeDiff.hljs.registerLanguage("c", c);
223+
CodeDiff.hljs.registerLanguage("c", c)
167224
```
168225

169226
## 从 0.x 版本迁移

README.md

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ This project references the following projects, and I would like to express my g
2222
- Github Code Diff
2323

2424
## Contents
25-
2625
- [Install](#Install)
2726
- [Getting started](#Getting-started)
2827
- [Vue3](#Vue3)
@@ -58,6 +57,24 @@ pnpm add @vue/composition-api
5857

5958
### Vue3
6059

60+
#### Register locally
61+
> Recommend using local registration for better tree-shaking support.
62+
```vue
63+
<script setup>
64+
import { CodeDiff } from 'v-code-diff'
65+
</script>
66+
67+
<template>
68+
<div>
69+
<CodeDiff
70+
old-string="12345"
71+
new-string="3456"
72+
output-format="side-by-side"
73+
/>
74+
</div>
75+
</template>
76+
```
77+
6178
#### Register globally
6279

6380
```ts
@@ -81,25 +98,38 @@ then
8198
</template>
8299
```
83100

84-
#### Register locally
85-
86-
Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.
87-
88101
### Vue2
89102

90-
#### Register globally
103+
#### Register locally
104+
> > Recommend using local registration for better tree-shaking support.
105+
```vue
106+
<script>
107+
import { CodeDiff } from 'v-code-diff'
108+
export default {
109+
components: {
110+
CodeDiff
111+
}
112+
}
113+
</script>
91114
115+
<template>
116+
<div>
117+
<CodeDiff
118+
old-string="12345"
119+
new-string="3456"
120+
output-format="side-by-side"
121+
/>
122+
</div>
123+
</template>
124+
```
125+
#### Register globally
92126
```ts
93127
import Vue from 'vue'
94128
import CodeDiff from 'v-code-diff'
95129

96130
Vue.use(CodeDiff)
97131
```
98132

99-
#### Register locally
100-
101-
Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.
102-
103133
## Demo
104134

105135
| | npm | cdn |
@@ -160,13 +190,40 @@ If the language you need is not included, you can manually import the relevant l
160190
```shell
161191
pnpm add highlight.js
162192
```
193+
#### Register locally
194+
> Recommend using local registration for better tree-shaking support.
195+
```vue
196+
<script>
197+
import { CodeDiff, hljs } from 'v-code-diff'
198+
import c from 'highlight.js/lib/languages/c'
199+
// Extend C language
200+
hljs.registerLanguage('c', c)
201+
export default {
202+
components: {
203+
CodeDiff,
204+
}
205+
}
206+
</script>
163207
208+
<template>
209+
<div>
210+
<CodeDiff
211+
old-string="#include <stdio.h>"
212+
new-string="#include <stdio.h>\nint a = 1;"
213+
output-format="side-by-side"
214+
language="c"
215+
/>
216+
</div>
217+
</template>
218+
```
219+
220+
#### Register globally
164221
```typescript
165-
import CodeDiff from 'v-code-diff';
222+
import CodeDiff from 'v-code-diff'
166223
// Extend C language
167-
import c from 'highlight.js/lib/languages/c';
224+
import c from 'highlight.js/lib/languages/c'
168225

169-
CodeDiff.hljs.registerLanguage('c', c);
226+
CodeDiff.hljs.registerLanguage('c', c)
170227
```
171228

172229
## Migrate from 0.x version

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function install(app: any) {
77

88
export {
99
CodeDiff,
10+
hljs,
1011
}
1112

1213
export default {

0 commit comments

Comments
 (0)