Skip to content

Commit

Permalink
<update> doc
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyFoxFN committed Jan 24, 2018
1 parent e1fd674 commit 30463f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions document/components/docs/en-US/create-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,19 @@ This module exports a function called `createAPI` with which you can invoke the
})
```
In this example, we create a component `Hello` which needs to be invoked in api form and we invoke it in another component.The focus is what `showHello()` does: invoking method `this.$createHello(config, renderFn)` to instantiate `Hello`.

### How to use in general JS files

In vue component, you could call by `this.$createHello(config, renderFn)` because the `this` is just a vue instance. But in general JS files, you need to call `$createHello` method by `Vue.prototype` or create a vue instance. As shown below:

```js
import Vue from 'vue'

Vue.prototype.$createHello(config, renderFn)

// or
const vm = new Vue()
vm.$createHello(config, renderFn)
```

There is another idea which used the mode of data-driven. For example, in vuex, you could use a global state to label whether to call the component, and watch this state in App.vue to handle this component.
4 changes: 2 additions & 2 deletions document/components/docs/zh-CN/create-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

### 如何在普通 js 文件中调用

一般当你在 vue 实例中,你可以直接通过 `this.$createHello(config, renderFn)` 调用该组件。而如果在普通 JS 中 this 不是 vue 实例,这时就需要通过 Vue.prototye 或者创建一个 vue 实例来调用`$createHello`方法了,比如:
一般当你在 vue 实例中,你可以直接通过 `this.$createHello(config, renderFn)` 调用该组件。而如果在普通 JS 中`this`不是 vue 实例,这时就需要通过`Vue.prototye`或者创建一个 vue 实例来调用`$createHello`方法了,比如:

```js
import Vue from 'vue'
Expand All @@ -133,4 +133,4 @@ const vm = new Vue()
vm.$createHello(config, renderFn)
```

还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,需要弹窗的时候去更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。
还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,在需要调用该组件时更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。

0 comments on commit 30463f3

Please sign in to comment.