You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 16, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: src/v2/guide/plugins.md
+21-25Lines changed: 21 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -4,78 +4,74 @@ type: guide
4
4
order: 304
5
5
---
6
6
7
-
## Writing a Plugin
7
+
## Viết plugin
8
8
9
-
Plugins usually add global-level functionality to Vue. There is no strictly defined scope for a plugin - there are typically several types of plugins you can write:
9
+
Thông thường thì các plugin được dùng để bổ sung tính năng cho Vue ở cấp toàn cục. Không có phạm vi ràng buộc cụ thể nào cho một plugin – nói chung bạn có thể viết một số kiểu plugin khác nhau như sau:
10
10
11
-
1.Add some global methods or properties. e.g.[vue-custom-element](https://github.com/karol-f/vue-custom-element)
11
+
1.Thêm một số phương thức hoặc thuộc tính toàn cục, ví dụ như[vue-custom-element](https://github.com/karol-f/vue-custom-element)
12
12
13
-
2.Add one or more global assets: directives/filters/transitions etc. e.g.[vue-touch](https://github.com/vuejs/vue-touch)
13
+
2.Thêm một hoặc nhiều directive/filter/transition vân vân, ví dụ như[vue-touch](https://github.com/vuejs/vue-touch)
14
14
15
-
3.Add some component options by global mixin. e.g.[vue-router](https://github.com/vuejs/vue-router)
15
+
3.Thêm tùy chọn cho component thông qua [mixin](mixins.html) cấp toàn cục, ví dụ như[vue-router](https://github.com/vuejs/vue-router)
16
16
17
-
4.Add some Vue instance methods by attaching them to Vue.prototype.
17
+
4.Thêm một số phương thức đối tượng (instance method) bằng cách đính kèm vào `Vue.prototype`.
18
18
19
-
5.A library that provides an API of its own, while at the same time injecting some combination of the above. e.g.[vue-router](https://github.com/vuejs/vue-router)
19
+
5.Một thư viện cung cấp API riêng và cùng lúc đó thêm một hoặc vài tính năng được liệt kê trên đây, ví dụ[vue-router](https://github.com/vuejs/vue-router)
20
20
21
-
A Vue.js plugin should expose an `install` method. The method will be called with the `Vue` constructor as the first argument, along with possible options:
21
+
Một plugin cho Vue nên cung cấp một phương thức `install`. Phương thức này sẽ được gọi với tham số đầu tiên là hàm dựng `Vue`, cùng với các tùy chọn khác:
22
22
23
23
```js
24
24
MyPlugin.install=function (Vue, options) {
25
-
// 1. add global method or property
25
+
// 1. Thêm phương thức hoặc thuộc tính cấp toàn cục
Use plugins by calling the `Vue.use()` global method:
51
+
Chúng ta sử dụng một plugin bằng cách gọi phương thức toàn cục `Vue.use()`:
56
52
57
53
```js
58
-
//calls `MyPlugin.install(Vue)`
54
+
//dòng code này sẽ gọi `MyPlugin.install(Vue)`
59
55
Vue.use(MyPlugin)
60
56
```
61
57
62
-
You can optionally pass in some options:
58
+
Bạn cũng có thể truyền thêm vào một số tùy chọn:
63
59
64
60
```js
65
61
Vue.use(MyPlugin, { someOption:true })
66
62
```
67
63
68
-
`Vue.use`automatically prevents you from using the same plugin more than once, so calling it multiple times on the same plugin will install the plugin only once.
64
+
`Vue.use`tự động ngăn không cho sử dụng một plugin nhiều lần, vì vậy cho dù chúng ta có gọi `Vue.use(MyPlugin)` mười lần thì `MyPlugin` cũng sẽ chỉ được cài đặt một lần thôi.
69
65
70
-
Some plugins provided by Vue.js official plugins such as `vue-router` automatically calls `Vue.use()`if `Vue` is available as a global variable. However in a module environment such as CommonJS, you always need to call `Vue.use()`explicitly:
66
+
Một số plugin tự động gọi `Vue.use()`nếu phát hiện thấy biến toàn cục `Vue`. Tuy nhiên trong một môi trường module, ví dụ như CommonJS, bạn cần phải gọi `Vue.use()`một cách tường minh:
71
67
72
68
```js
73
-
//When using CommonJS via Browserify or Webpack
69
+
//Khi dùng CommonJS với Browserify hoặc Webpack…
74
70
var Vue =require('vue')
75
71
var VueRouter =require('vue-router')
76
72
77
-
//Don't forget to call this
73
+
//…đừng quên gọi Vue.use()
78
74
Vue.use(VueRouter)
79
75
```
80
76
81
-
Checkout[awesome-vue](https://github.com/vuejs/awesome-vue#components--libraries)for a huge collection of community-contributed plugins and libraries.
77
+
Repository[awesome-vue](https://github.com/vuejs/awesome-vue#components--libraries)chứa rất nhiều plugin và thư viện do cộng đồng đóng góp – khi thấy buồn bạn cứ đến chơi.
0 commit comments