提交 754f1237 编写于 作者: A AmyFoxFN

<update> doc

上级 c1a4a5f4
......@@ -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.
......@@ -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'
......@@ -133,4 +133,4 @@ const vm = new Vue()
vm.$createHello(config, renderFn)
```
还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,需要弹窗的时候去更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。
还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,在需要调用该组件时更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册