8000 Finish translation · vuejs-vn/vuejs.org@4276330 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

Commit 4276330

Browse files
committed
Finish translation
1 parent 2d3ae68 commit 4276330

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/v2/guide/plugins.md

Lines changed: 21 additions & 25 deletions
56
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,74 @@ type: guide
44
order: 304
55
---
66

7-
## Writing a Plugin
7+
## Viết plugin
88

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:
1010

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)
1212

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)
1414

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)
1616

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`.
1818

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)
2020

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:
2222

2323
``` js
2424
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
2626
Vue.myGlobalMethod = function () {
27-
// something logic ...
2827
}
2928

30-
// 2. add a global asset
29+
// 2. Thêm một directive cấp toàn cục
3130
Vue.directive('my-directive', {
3231
bind (el, binding, vnode, oldVnode) {
33-
// something logic ...
3432
}
3533
...
3634
})
3735

38-
// 3. inject some component options
36+
// 3. Thêm một số tùy chọn cho component
3937
Vue.mixin({
4038
created: function () {
41-
// something logic ...
4239
}
4340
...
4441
})
4542

46-
// 4. add an instance method
43+
// 4. Thêm một phương thức đối tượng
4744
Vue.prototype.$myMethod = function (methodOptions) {
48-
// something logic ...
4945
}
5046
}
5147
```
5248

53-
## Using a Plugin
49+
## Sử dụng plugin
5450

55-
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()`:
5652

5753
``` js
58-
// calls `MyPlugin.install(Vue)`
54+
// dòng code này sẽ gọi `MyPlugin.install(Vue)`
5955
Vue.use(MyPlugin)
60
```
6157

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:
6359

6460
``` js
6561
Vue.use(MyPlugin, { someOption: true })
6662
```
6763

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.
6965

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:
7167

7268
``` js
73-
// When using CommonJS via Browserify or Webpack
69+
// Khi dùng CommonJS với Browserify hoặc Webpack
7470
var Vue = require('vue')
7571
var VueRouter = require('vue-router')
7672

77-
// Don't forget to call this
73+
// …đừng quên gọi Vue.use()
7874
Vue.use(VueRouter)
7975
```
8076

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

Comments
 (0)
0