Skip to content

Commit 1f2e6b3

Browse files
committed
fix plugins
1 parent 49387d4 commit 1f2e6b3

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

src/api/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,9 @@ type: api
11521152

11531153
- **用法:**
11541154

1155-
如果 Vue 实例在实例化时没有收到 el 选项,则它处于“未挂载”状态,没有关联的 DOM 元素或片断。可以使用 vm.$mount() 手动地挂载一个未挂载的实例。
1155+
如果 Vue 实例在实例化时没有收到 el 选项,则它处于“未挂载”状态,没有关联的 DOM 元素或片断。可以使用 `vm.$mount()` 手动地挂载一个未挂载的实例。
11561156

1157-
如果没有"elementOrSelector"参数,模板将被渲染为文档之外的的元素,并且你必须使用原生DOM API把它插入文档中。
1157+
如果没有 `elementOrSelector` 参数,模板将被渲染为文档之外的的元素,并且你必须使用原生DOM API把它插入文档中。
11581158

11591159
这个方法返回实例自身,因而可以链式调用其它实例方法。
11601160

@@ -1226,31 +1226,31 @@ type: api
12261226

12271227
完全销毁一个实例。清理它与其它实例的连接,解绑它的全部指令及事件监听器。
12281228

1229-
"beforeDestroy"和"destroyed"之间触发。
1229+
`beforeDestroy``destroyed` 之间触发。
12301230

1231-
<p class="tip">在大多数场景中你不应该调用这个方法。最好使用"v-if"和"v-for"指令以数据驱动的方式控制子组件的生命周期。</p>
1231+
<p class="tip">在大多数场景中你不应该调用这个方法。最好使用 `v-if` 和 `v-for` 指令以数据驱动的方式控制子组件的生命周期。</p>
12321232

12331233
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
12341234

1235-
## Directives
1235+
## 指令
12361236

12371237
### v-text
12381238

1239-
- **Expects:** `string`
1239+
- **类型:** `string`
12401240

1241-
- **Details:**
1241+
- **详细:**
12421242

12431243
Updates the element's `textContent`. If you need to update the part of `textContent`, you should use `{% raw %}{{ Mustache }}{% endraw %}` interpolations.
12441244

1245-
- **Example:**
1245+
- **示例:**
12461246

12471247
```html
12481248
<span v-text="msg"></span>
12491249
<!-- same as -->
12501250
<span>{{msg}}</span>
12511251
```
12521252

1253-
- **See also:** [Data Binding Syntax - interpolations](/guide/syntax.html#Text)
1253+
- **另见:** [Data Binding Syntax - interpolations](/guide/syntax.html#Text)
12541254

12551255
### v-html
12561256

src/guide/plugins.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,84 @@ type: guide
44
order: 18
55
---
66

7-
## Writing a Plugin
7+
## 开发插件
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:
109

11-
1. Add some global methods or properties. e.g. [vue-element](https://github.com/vuejs/vue-element)
10+
插件通常会为Vue添加全局功能。插件的范围没有限制--一般有下面几种:
1211

13-
2. Add one or more global assets: directives/filters/transitions etc. e.g. [vue-touch](https://github.com/vuejs/vue-touch)
12+
1. 添加全局方法或者属性,如: [vue-element](https://github.com/vuejs/vue-element)
1413

15-
3. Add some component options by global mixin. e.g. [vuex](https://github.com/vuejs/vuex)
14+
2. 添加全局资源:指令/过滤器/过渡等。如 vue-touch [vue-touch](https://github.com/vuejs/vue-touch)
1615

17-
4. Add some Vue instance methods by attaching them to Vue.prototype.
16+
3. 通过全局 mixin方法 添加一些组件选项。 如: [vuex](https://github.com/vuejs/vuex)
1817

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)
18+
4. 添加 Vue 实例方法,通过把它们添加到 Vue.prototype 上实现。
2019

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:
20+
5. A一个库,提供自己的 API,同时提供上面提到的一个或多个功能。如 [vue-router](https://github.com/vuejs/vue-router)
21+
22+
Vue.js 的插件应当有一个公开方法 `install` 。这个方法的第一个参数是 `Vue` 构造器 , 第二个参数是一个可选的选项对象:
2223

2324
``` js
2425
MyPlugin.install = function (Vue, options) {
25-
// 1. add global method or property
26+
// 1. 添加全局方法或属性
2627
Vue.myGlobalMethod = function () {
2728
// something logic ...
2829
}
2930

30-
// 2. add a global asset
31+
// 2. 添加全局资源
3132
Vue.directive('my-directive', {
3233
bind (el, binding, vnode, oldVnode) {
3334
// something logic ...
3435
}
3536
...
3637
})
3738

38-
// 3. inject some component options
39+
// 3. 注入组件
3940
Vue.mixin({
4041
created: function () {
4142
// something logic ...
4243
}
4344
...
4445
})
4546

46-
// 4. add an instance method
47+
// 4. 添加事例方法
4748
Vue.prototype.$myMethod = function (options) {
4849
// something logic ...
4950
}
5051
}
5152
```
5253

53-
## Using a Plugin
54+
## 使用插件
5455

55-
Use plugins by calling the `Vue.use()` global method:
56+
通过 Vue.use() 全局方法使用插件:
5657

5758
``` js
58-
// calls `MyPlugin.install(Vue)`
59+
// 调用 `MyPlugin.install(Vue)`
5960
Vue.use(MyPlugin)
6061
```
6162

62-
You can optionally pass in some options:
63+
也可以传入一个选项对象:
6364

6465
``` js
6566
Vue.use(MyPlugin, { someOption: true })
6667
```
6768

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` 会自动阻止注册相同插件多次,届时只会注册一次该插件。
6970

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:
71+
一些插件,如 `vue-router` 如果 `Vue` 是全局变量则自动调用`Vue.use()` 。不过在模块环境中应当始终显式调用 `Vue.use()` :
7172

7273
``` js
73-
// When using CommonJS via Browserify or Webpack
74+
// 通过 Browserify 或 Webpack 使用 CommonJS 兼容模块
7475
var Vue = require('vue')
7576
var VueRouter = require('vue-router')
7677

77-
// Don't forget to call this
78+
// 不要忘了调用此方法
7879
Vue.use(VueRouter)
7980
```
8081

81-
Checkout [awesome-vue](https://github.com/vuejs/awesome-vue#libraries--plugins) for a huge collection of community-contributed plugins and libraries.
82+
[awesome-vue](https://github.com/vuejs/awesome-vue#libraries--plugins) 集合了来自社区贡献的数以千计的插件和库。
83+
84+
8285

8386

8487
***

0 commit comments

Comments
 (0)