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
Updates the element's `textContent`. If you need to update the part of `textContent`, you should use `{% raw %}{{ Mustache }}{% endraw %}` interpolations.
Copy file name to clipboardExpand all lines: src/guide/plugins.md
+24-21Lines changed: 24 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -4,81 +4,84 @@ type: guide
4
4
order: 18
5
5
---
6
6
7
-
## Writing a Plugin
7
+
## 开发插件
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:
10
9
11
-
1. Add some global methods or properties. e.g. [vue-element](https://github.com/vuejs/vue-element)
10
+
插件通常会为Vue添加全局功能。插件的范围没有限制--一般有下面几种:
12
11
13
-
2. Add one or more global assets: directives/filters/transitions etc. e.g. [vue-touch](https://github.com/vuejs/vue-touch)
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)
18
+
4. 添加 Vue 实例方法,通过把它们添加到 Vue.prototype 上实现。
20
19
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:
Use plugins by calling the `Vue.use()` global method:
56
+
通过 Vue.use() 全局方法使用插件:
56
57
57
58
```js
58
-
//calls `MyPlugin.install(Vue)`
59
+
//调用 `MyPlugin.install(Vue)`
59
60
Vue.use(MyPlugin)
60
61
```
61
62
62
-
You can optionally pass in some options:
63
+
也可以传入一个选项对象:
63
64
64
65
```js
65
66
Vue.use(MyPlugin, { someOption:true })
66
67
```
67
68
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.
69
+
`Vue.use`会自动阻止注册相同插件多次,届时只会注册一次该插件。
69
70
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:
0 commit comments