提交 a492457d 编写于 作者: A AmyFoxFN

docs build

上级 754f1237
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"><meta name=x5-cache content=disable><title>cube-ui Document</title><link href=/cube-ui/css/app.a1b6487c112e6028233e378dfc1c8889.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/cube-ui/js/manifest.cd7383a602e6f720be6e.js></script><script type=text/javascript src=/cube-ui/js/vendor.4bef0c72c513e604f246.js></script><script type=text/javascript src=/cube-ui/js/app.30b2fe9216fb3d5b9491.js></script></body></html>
\ No newline at end of file
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"><meta name=x5-cache content=disable><title>cube-ui Document</title><link href=/cube-ui/css/app.a1b6487c112e6028233e378dfc1c8889.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/cube-ui/js/manifest.dd8422c8f6d0447b623e.js></script><script type=text/javascript src=/cube-ui/js/vendor.4bef0c72c513e604f246.js></script><script type=text/javascript src=/cube-ui/js/app.30b2fe9216fb3d5b9491.js></script></body></html>
\ No newline at end of file
webpackJsonp([20],{482:function(s,t,a){s.exports=a(571)},571:function(s,t,a){var n=a(11)(null,a(572),null,null,null);s.exports=n.exports},572:function(s,t){s.exports={render:function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("section",[a("h2",{attrs:{id:"create-api模块"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-create-api模块-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" create-api 模块")]),s._v(" "),s._m(0),s._v(" "),a("h3",{attrs:{id:"createAPI(Vue,Component,[events,single])"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-createAPI(Vue,Component,[events,single])-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" createAPI(Vue, Component, [events, single])")]),s._v(" "),s._m(1),s._v(" "),a("p",[s._v("我们先编写一个 Hello.vue 组件:")]),s._v(" "),s._m(2),s._v(" "),s._m(3),s._v(" "),s._m(4),s._v(" "),s._m(5),s._v(" "),a("h3",{attrs:{id:"如何在普通js文件中调用"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-如何在普通js文件中调用-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" 如何在普通 js 文件中调用")]),s._v(" "),s._m(6),s._v(" "),s._m(7),s._v(" "),a("p",[s._v("还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,在需要调用该组件时更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。")])])},staticRenderFns:[function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("该模块默认暴露出一个 "),a("code",{pre:!0},[s._v("createAPI")]),s._v(" 函数,可以实现以 API 的形式调用自定义组件。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ul",[a("li",[a("p",[s._v("参数:")]),s._v(" "),a("ul",[a("li",[a("code",{pre:!0},[s._v("{Function} Vue")]),s._v(" Vue 函数")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Function | Object} Component")]),s._v(" Vue 组件,组件必须有 name")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Array} [events]")]),s._v(" 组件实例 emit 的事件名集合")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" 是否为单例")])])]),s._v(" "),a("li",[a("p",[s._v("用法:")]),s._v(" "),a("ul",[a("li",[s._v("该方法在 Vue 的 prototype 上增加一个名为 "),a("code",{pre:!0},[s._v("$create{camelize(Component.name)}")]),s._v(" 的方法,这样就可以在其他组件中直接通过 "),a("code",{pre:!0},[s._v("const instance = this.$createAaBb(config, [renderFn, single])")]),s._v(" 这样来实例化组件了,而且这个实例化组件的元素是被附加到 "),a("code",{pre:!0},[s._v("body")]),s._v(" 元素下的;关于 "),a("code",{pre:!0},[s._v("$createAaBb")]),s._v(" 的参数:\n"),a("ul",[a("li",[a("code",{pre:!0},[s._v("{Object} config")]),s._v(" 组件配置参数,默认所有的值都会当做 props 传给组件,但是要排除 "),a("code",{pre:!0},[s._v("events")]),s._v(" 中的事件(默认会做转换,例如:"),a("code",{pre:!0},[s._v("events")]),s._v(" 的值为 "),a("code",{pre:!0},[s._v("['click']")]),s._v(",那么 "),a("code",{pre:!0},[s._v("config")]),s._v(" 中的 "),a("code",{pre:!0},[s._v("onClick")]),s._v(" 就是作为 "),a("code",{pre:!0},[s._v("click")]),s._v(" 事件的回调函数,而不是作为 props 传递给组件)。")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Function} [renderFn]")]),s._v(" 可选参数,用于生成子 VNode 节点,一般场景是处理 slot。")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" 可选参数,创建的时候决定是否是单例的,优先级更高,如果没有传入 renderFn 的话,single 的值就是第二个参数的值。")])])]),s._v(" "),a("li",[s._v("注意调用后的返回值 "),a("code",{pre:!0},[s._v("instance")]),s._v(" 就是组件实例,这个实例会被"),a("strong",[s._v("附加")]),s._v("或者"),a("strong",[s._v("代理")]),s._v(" "),a("code",{pre:!0},[s._v("remove")]),s._v(" 方法,如果调用了,该实例就会被销毁且会从 "),a("code",{pre:!0},[s._v("body")]),s._v(" 下移除。")])])]),s._v(" "),a("li",[a("p",[s._v("示例:")])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-html"}},[a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@click")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"clickHandler"')]),s._v(">")]),s._v("\n {{content}}\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"other"')]),s._v(">")]),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n"),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n\n"),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"text/ecmascript-6"')]),s._v(">")]),a("span",{attrs:{class:"javascript"}},[s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'hello'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("props")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("String")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("default")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'Hello'")]),s._v("\n }\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n clickHandler(e) {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$emit("),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", e)\n }\n }\n }\n")]),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(">")]),s._v("\n")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("然后我们再通过 "),a("code",{pre:!0},[s._v("createAPI")]),s._v(" 把 Hello.vue 变成一个 API 式调用的组件并调用。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Hello "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'./Hello.vue'")]),s._v("\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 引入 Style 加载基础样式")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("/* eslint-disable no-unused-vars */")]),s._v("\n Style,\n Dialog,\n createAPI\n } "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'cube-ui'")]),s._v("\n\n Vue.use(Dialog)\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 创建 this.$createHello API")]),s._v("\n createAPI(Vue, Hello, ["),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v("], "),a("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v(")\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 初始化 Vue")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("el")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'#app'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("render")]),s._v(": "),a("span",{attrs:{class:"hljs-function"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("function")]),s._v(" ("),a("span",{attrs:{class:"hljs-params"}},[s._v("h")]),s._v(") ")]),s._v("{\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" h("),a("span",{attrs:{class:"hljs-string"}},[s._v("'button'")]),s._v(", {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("on")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("click")]),s._v(": "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".showHello\n }\n }, ["),a("span",{attrs:{class:"hljs-string"}},[s._v("'Show Hello'")]),s._v("])\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n showHello() {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 直接调用")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 传入配置对象,默认传入的所有对象全都当做 props 传入组件")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 除了在调用 createAPI 的时候传入了 events,这里对应的就是")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// on{event name} 会被当做事件回调处理")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" instance = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createHello({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'My Hello Content'")]),s._v(",\n onClick(e) {\n "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),a("span",{attrs:{class:"hljs-string"}},[s._v("'Hello component clicked.'")]),s._v(")\n }\n }, "),a("span",{attrs:{class:"hljs-comment"}},[s._v("/* renderFn */")]),s._v(" (createElement) => {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" [\n createElement("),a("span",{attrs:{class:"hljs-string"}},[s._v("'p'")]),s._v(", {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("slot")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'other'")]),s._v("\n }, "),a("span",{attrs:{class:"hljs-string"}},[s._v("'other content'")]),s._v(")\n ]\n })\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 通过 Vue 组件的 $on 也是可以监听的,看使用场景")]),s._v("\n instance.$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", (e) => {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" $dialog = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createDialog({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'点击确定关闭当前实例'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("icon")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'cubeic-alert'")]),s._v("\n })\n $dialog.show()\n\n $dialog.$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(", () => {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 销毁实例")]),s._v("\n instance.remove()\n }).$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(", () => {\n "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),a("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(")\n })\n })\n }\n }\n })\n")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("示例中就是创建了一个需要 API 调用的组件 "),a("code",{pre:!0},[s._v("Hello")]),s._v(",然后在其他组件中去使用,重点就是 "),a("code",{pre:!0},[s._v("showHello()")]),s._v(" 方法做的事情:调用 "),a("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" 实现组件的实例化。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("一般当你在 vue 实例中,你可以直接通过 "),a("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" 调用该组件。而如果在普通 JS 中"),a("code",{pre:!0},[s._v("this")]),s._v("不是 vue 实例,这时就需要通过"),a("code",{pre:!0},[s._v("Vue.prototye")]),s._v("或者创建一个 vue 实例来调用"),a("code",{pre:!0},[s._v("$createHello")]),s._v("方法了,比如:")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n\nVue.prototype.$createHello(config, renderFn)\n\n"),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 或者")]),s._v("\n"),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" vm = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue()\nvm.$createHello(config, renderFn)\n")])])}]}}});
\ No newline at end of file
webpackJsonp([20],{482:function(s,t,a){s.exports=a(571)},571:function(s,t,a){var n=a(11)(null,a(572),null,null,null);s.exports=n.exports},572:function(s,t){s.exports={render:function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("section",[a("h2",{attrs:{id:"create-api模块"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-create-api模块-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" create-api 模块")]),s._v(" "),s._m(0),s._v(" "),a("h3",{attrs:{id:"createAPI(Vue,Component,[events,single])"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-createAPI(Vue,Component,[events,single])-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" createAPI(Vue, Component, [events, single])")]),s._v(" "),s._m(1),s._v(" "),a("p",[s._v("我们先编写一个 Hello.vue 组件:")]),s._v(" "),s._m(2),s._v(" "),s._m(3),s._v(" "),s._m(4),s._v(" "),s._m(5),s._v(" "),a("h3",{attrs:{id:"如何在普通js文件中调用"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-如何在普通js文件中调用-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" 如何在普通 js 文件中调用")]),s._v(" "),s._m(6),s._v(" "),s._m(7),s._v(" "),a("p",[s._v("还有一种思路是通过数据驱动,比如用 vuex 维护一个全局 state,需要弹窗的时候去更新状态,然后在 App.vue 里去 watch 这个状态变化来调用该组件。")])])},staticRenderFns:[function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("该模块默认暴露出一个 "),a("code",{pre:!0},[s._v("createAPI")]),s._v(" 函数,可以实现以 API 的形式调用自定义组件。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ul",[a("li",[a("p",[s._v("参数:")]),s._v(" "),a("ul",[a("li",[a("code",{pre:!0},[s._v("{Function} Vue")]),s._v(" Vue 函数")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Function | Object} Component")]),s._v(" Vue 组件,组件必须有 name")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Array} [events]")]),s._v(" 组件实例 emit 的事件名集合")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" 是否为单例")])])]),s._v(" "),a("li",[a("p",[s._v("用法:")]),s._v(" "),a("ul",[a("li",[s._v("该方法在 Vue 的 prototype 上增加一个名为 "),a("code",{pre:!0},[s._v("$create{camelize(Component.name)}")]),s._v(" 的方法,这样就可以在其他组件中直接通过 "),a("code",{pre:!0},[s._v("const instance = this.$createAaBb(config, [renderFn, single])")]),s._v(" 这样来实例化组件了,而且这个实例化组件的元素是被附加到 "),a("code",{pre:!0},[s._v("body")]),s._v(" 元素下的;关于 "),a("code",{pre:!0},[s._v("$createAaBb")]),s._v(" 的参数:\n"),a("ul",[a("li",[a("code",{pre:!0},[s._v("{Object} config")]),s._v(" 组件配置参数,默认所有的值都会当做 props 传给组件,但是要排除 "),a("code",{pre:!0},[s._v("events")]),s._v(" 中的事件(默认会做转换,例如:"),a("code",{pre:!0},[s._v("events")]),s._v(" 的值为 "),a("code",{pre:!0},[s._v("['click']")]),s._v(",那么 "),a("code",{pre:!0},[s._v("config")]),s._v(" 中的 "),a("code",{pre:!0},[s._v("onClick")]),s._v(" 就是作为 "),a("code",{pre:!0},[s._v("click")]),s._v(" 事件的回调函数,而不是作为 props 传递给组件)。")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Function} [renderFn]")]),s._v(" 可选参数,用于生成子 VNode 节点,一般场景是处理 slot。")]),s._v(" "),a("li",[a("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" 可选参数,创建的时候决定是否是单例的,优先级更高,如果没有传入 renderFn 的话,single 的值就是第二个参数的值。")])])]),s._v(" "),a("li",[s._v("注意调用后的返回值 "),a("code",{pre:!0},[s._v("instance")]),s._v(" 就是组件实例,这个实例会被"),a("strong",[s._v("附加")]),s._v("或者"),a("strong",[s._v("代理")]),s._v(" "),a("code",{pre:!0},[s._v("remove")]),s._v(" 方法,如果调用了,该实例就会被销毁且会从 "),a("code",{pre:!0},[s._v("body")]),s._v(" 下移除。")])])]),s._v(" "),a("li",[a("p",[s._v("示例:")])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-html"}},[a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@click")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"clickHandler"')]),s._v(">")]),s._v("\n {{content}}\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"other"')]),s._v(">")]),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n"),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n\n"),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"text/ecmascript-6"')]),s._v(">")]),a("span",{attrs:{class:"javascript"}},[s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'hello'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("props")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("String")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("default")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'Hello'")]),s._v("\n }\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n clickHandler(e) {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$emit("),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", e)\n }\n }\n }\n")]),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(">")]),s._v("\n")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("然后我们再通过 "),a("code",{pre:!0},[s._v("createAPI")]),s._v(" 把 Hello.vue 变成一个 API 式调用的组件并调用。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Hello "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'./Hello.vue'")]),s._v("\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 引入 Style 加载基础样式")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("/* eslint-disable no-unused-vars */")]),s._v("\n Style,\n Dialog,\n createAPI\n } "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'cube-ui'")]),s._v("\n\n Vue.use(Dialog)\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 创建 this.$createHello API")]),s._v("\n createAPI(Vue, Hello, ["),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v("], "),a("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v(")\n\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 初始化 Vue")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("el")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'#app'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("render")]),s._v(": "),a("span",{attrs:{class:"hljs-function"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("function")]),s._v(" ("),a("span",{attrs:{class:"hljs-params"}},[s._v("h")]),s._v(") ")]),s._v("{\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" h("),a("span",{attrs:{class:"hljs-string"}},[s._v("'button'")]),s._v(", {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("on")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("click")]),s._v(": "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".showHello\n }\n }, ["),a("span",{attrs:{class:"hljs-string"}},[s._v("'Show Hello'")]),s._v("])\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n showHello() {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 直接调用")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 传入配置对象,默认传入的所有对象全都当做 props 传入组件")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 除了在调用 createAPI 的时候传入了 events,这里对应的就是")]),s._v("\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// on{event name} 会被当做事件回调处理")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" instance = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createHello({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'My Hello Content'")]),s._v(",\n onClick(e) {\n "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),a("span",{attrs:{class:"hljs-string"}},[s._v("'Hello component clicked.'")]),s._v(")\n }\n }, "),a("span",{attrs:{class:"hljs-comment"}},[s._v("/* renderFn */")]),s._v(" (createElement) => {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" [\n createElement("),a("span",{attrs:{class:"hljs-string"}},[s._v("'p'")]),s._v(", {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("slot")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'other'")]),s._v("\n }, "),a("span",{attrs:{class:"hljs-string"}},[s._v("'other content'")]),s._v(")\n ]\n })\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 通过 Vue 组件的 $on 也是可以监听的,看使用场景")]),s._v("\n instance.$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", (e) => {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" $dialog = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createDialog({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'点击确定关闭当前实例'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("icon")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'cubeic-alert'")]),s._v("\n })\n $dialog.show()\n\n $dialog.$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(", () => {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 销毁实例")]),s._v("\n instance.remove()\n }).$on("),a("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(", () => {\n "),a("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),a("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(")\n })\n })\n }\n }\n })\n")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("示例中就是创建了一个需要 API 调用的组件 "),a("code",{pre:!0},[s._v("Hello")]),s._v(",然后在其他组件中去使用,重点就是 "),a("code",{pre:!0},[s._v("showHello()")]),s._v(" 方法做的事情:调用 "),a("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" 实现组件的实例化。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("一般当你在 vue 实例中,你可以直接通过 "),a("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" 调用该组件。而如果在普通 JS 中 this 不是 vue 实例,这时就需要通过 Vue.prototye 或者创建一个 vue 实例来调用"),a("code",{pre:!0},[s._v("$createHello")]),s._v("方法了,比如:")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n\nVue.prototype.$createHello(config, renderFn)\n\n"),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 或者")]),s._v("\n"),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" vm = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue()\nvm.$createHello(config, renderFn)\n")])])}]}}});
\ No newline at end of file
webpackJsonp([45],{457:function(s,t,e){s.exports=e(521)},521:function(s,t,e){var a=e(11)(null,e(522),null,null,null);s.exports=a.exports},522:function(s,t){s.exports={render:function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("section",[e("h2",{attrs:{id:"create-apimodule"}},[e("a",{staticClass:"anchor",attrs:{href:"#cube-create-apimodule-anchor","aria-hidden":"true"}},[e("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[e("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" create-api module")]),s._v(" "),s._m(0),s._v(" "),e("h3",{attrs:{id:"createAPI(Vue,Component,[events,single])"}},[e("a",{staticClass:"anchor",attrs:{href:"#cube-createAPI(Vue,Component,[events,single])-anchor","aria-hidden":"true"}},[e("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[e("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" createAPI(Vue, Component, [events, single])")]),s._v(" "),s._m(1)])},staticRenderFns:[function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("p",[s._v("This module exports a function called "),e("code",{pre:!0},[s._v("createAPI")]),s._v(" with which you can invoke the custom component which has been instantiated in api form.")])},function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("ul",[e("li",[e("p",[s._v("Parameters:")]),s._v(" "),e("ul",[e("li",[e("code",{pre:!0},[s._v("{Function} Vue")]),s._v(" Vue function")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Function | Object} Component")]),s._v(" Vue component which must contains "),e("code",{pre:!0},[s._v("name")])]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Array} [events]")]),s._v(" the collection of the instantiated Vue Component's event name")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" whether singleton")])])]),s._v(" "),e("li",[e("p",[s._v("Usage:")]),s._v(" "),e("ul",[e("li",[s._v("This method will add a method which is named "),e("code",{pre:!0},[s._v("$create{camelize(Component.name)}")]),s._v(" to Vue's prototype, so you can instantiate the Vue component by "),e("code",{pre:!0},[s._v("const instance = this.$createAaBb(config, [renderFn, single])")]),s._v(" in other components. The instantiated component's template content will be attached to "),e("code",{pre:!0},[s._v("body")]),s._v(" element.The parameters of the "),e("code",{pre:!0},[s._v("$createAaBb")]),s._v("\n"),e("ul",[e("li",[e("code",{pre:!0},[s._v("{Object} config")]),s._v(" It will be passed to the component as its props except the events in "),e("code",{pre:!0},[s._v("events")]),s._v("(It will transform by default, eg: If "),e("code",{pre:!0},[s._v("events")]),s._v(" has value "),e("code",{pre:!0},[s._v("['click']")]),s._v(", then the prop "),e("code",{pre:!0},[s._v("onClick")]),s._v(" will be treated as component's event and not component's props).")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Function} [renderFn]")]),s._v(" Optional, used to generate the VNode child node in the slot scene in general.")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" Optional, whether the instantiated component is a singleton or not. If two parameters are provided and the "),e("code",{pre:!0},[s._v("renderFn")]),s._v("'s type is not function, then the "),e("code",{pre:!0},[s._v("single")]),s._v(" value is the sencond parameter's value.")])])]),s._v(" "),e("li",[s._v("The return of the method "),e("code",{pre:!0},[s._v("instance")]),s._v(" is a instantiated Vue component,and the "),e("code",{pre:!0},[s._v("remove")]),s._v(" method will be "),e("strong",[s._v("attached")]),s._v(" to this instance.You can invoke the "),e("code",{pre:!0},[s._v("remove")]),s._v(" method to destroy the component and detach the component's content from "),e("code",{pre:!0},[s._v("body")]),s._v(" element.")])])]),s._v(" "),e("li",[e("p",[s._v("Example:")]),s._v(" "),e("p",[s._v("First we create Hello.vue component:")]),s._v(" "),e("pre",{pre:!0},[e("code",{attrs:{"v-pre":"",class:"language-html"}},[e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("@click")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"clickHandler"')]),s._v(">")]),s._v("\n {{content}}\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"other"')]),s._v(">")]),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(">")]),s._v("\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n"),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n\n"),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"text/ecmascript-6"')]),s._v(">")]),e("span",{attrs:{class:"javascript"}},[s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'hello'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("props")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("String")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("default")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'Hello'")]),s._v("\n }\n },\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n clickHandler(e) {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$emit("),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", e)\n }\n }\n }\n")]),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(">")]),s._v("\n")])]),s._v(" "),e("p",[s._v("Then we make Hello.vue to an API style component by calling the "),e("code",{pre:!0},[s._v("createAPI")]),s._v(" method.")]),s._v(" "),e("pre",{pre:!0},[e("code",{attrs:{"v-pre":"",class:"language-js"}},[s._v(" "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Hello "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'./Hello.vue'")]),s._v("\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// import Style to load the base style")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* eslint-disable no-unused-vars */")]),s._v("\n Style,\n Dialog,\n createAPI\n } "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'cube-ui'")]),s._v("\n\n Vue.use(Dialog)\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// create this.$createHello API")]),s._v("\n createAPI(Vue, Hello, ["),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v("], "),e("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v(")\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// init Vue")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("el")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'#app'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("render")]),s._v(": "),e("span",{attrs:{class:"hljs-function"}},[e("span",{attrs:{class:"hljs-keyword"}},[s._v("function")]),s._v(" ("),e("span",{attrs:{class:"hljs-params"}},[s._v("h")]),s._v(") ")]),s._v("{\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" h("),e("span",{attrs:{class:"hljs-string"}},[s._v("'button'")]),s._v(", {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("on")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("click")]),s._v(": "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".showHello\n }\n }, ["),e("span",{attrs:{class:"hljs-string"}},[s._v("'Show Hello'")]),s._v("])\n },\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n showHello() {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* The first parameter of `$createHello` will be passed to the component as its props except the events in `events`(It will transform by default, eg: If `events` has value `['click']`, then the prop `onClick` will be treated as component's event and not component's props) */")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" instance = "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createHello({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'My Hello Content'")]),s._v(",\n onClick(e) {\n "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),e("span",{attrs:{class:"hljs-string"}},[s._v("'Hello component clicked.'")]),s._v(")\n }\n }, "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* renderFn */")]),s._v(" (createElement) => {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" [\n createElement("),e("span",{attrs:{class:"hljs-string"}},[s._v("'p'")]),s._v(", {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("slot")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'other'")]),s._v("\n }, "),e("span",{attrs:{class:"hljs-string"}},[s._v("'other content'")]),s._v(")\n ]\n })\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// Also, the event hanlder can be registered by instance's `$on` method")]),s._v("\n instance.$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", (e) => {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" $dialog = "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createDialog({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'click confirm to remove current instance'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("icon")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'cubeic-alert'")]),s._v("\n })\n $dialog.show()\n\n $dialog.$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(", () => {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// remove instance")]),s._v("\n instance.remove()\n }).$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(", () => {\n "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),e("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(")\n })\n })\n }\n }\n })\n")])]),s._v(" "),e("p",[s._v("In this example, we create a component "),e("code",{pre:!0},[s._v("Hello")]),s._v(" which needs to be invoked in api form and we invoke it in another component.The focus is what "),e("code",{pre:!0},[s._v("showHello()")]),s._v(" does: invoking method "),e("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" to instantiate "),e("code",{pre:!0},[s._v("Hello")]),s._v(".")])])])}]}}});
\ No newline at end of file
webpackJsonp([45],{457:function(s,t,e){s.exports=e(521)},521:function(s,t,e){var a=e(11)(null,e(522),null,null,null);s.exports=a.exports},522:function(s,t){s.exports={render:function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("section",[e("h2",{attrs:{id:"create-apimodule"}},[e("a",{staticClass:"anchor",attrs:{href:"#cube-create-apimodule-anchor","aria-hidden":"true"}},[e("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[e("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" create-api module")]),s._v(" "),s._m(0),s._v(" "),e("h3",{attrs:{id:"createAPI(Vue,Component,[events,single])"}},[e("a",{staticClass:"anchor",attrs:{href:"#cube-createAPI(Vue,Component,[events,single])-anchor","aria-hidden":"true"}},[e("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[e("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" createAPI(Vue, Component, [events, single])")]),s._v(" "),s._m(1),s._v(" "),e("h3",{attrs:{id:"HowtouseingeneralJSfiles"}},[e("a",{staticClass:"anchor",attrs:{href:"#cube-HowtouseingeneralJSfiles-anchor","aria-hidden":"true"}},[e("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[e("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" How to use in general JS files")]),s._v(" "),s._m(2),s._v(" "),s._m(3),s._v(" "),e("p",[s._v("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.")])])},staticRenderFns:[function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("p",[s._v("This module exports a function called "),e("code",{pre:!0},[s._v("createAPI")]),s._v(" with which you can invoke the custom component which has been instantiated in api form.")])},function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("ul",[e("li",[e("p",[s._v("Parameters:")]),s._v(" "),e("ul",[e("li",[e("code",{pre:!0},[s._v("{Function} Vue")]),s._v(" Vue function")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Function | Object} Component")]),s._v(" Vue component which must contains "),e("code",{pre:!0},[s._v("name")])]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Array} [events]")]),s._v(" the collection of the instantiated Vue Component's event name")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" whether singleton")])])]),s._v(" "),e("li",[e("p",[s._v("Usage:")]),s._v(" "),e("ul",[e("li",[s._v("This method will add a method which is named "),e("code",{pre:!0},[s._v("$create{camelize(Component.name)}")]),s._v(" to Vue's prototype, so you can instantiate the Vue component by "),e("code",{pre:!0},[s._v("const instance = this.$createAaBb(config, [renderFn, single])")]),s._v(" in other components. The instantiated component's template content will be attached to "),e("code",{pre:!0},[s._v("body")]),s._v(" element.The parameters of the "),e("code",{pre:!0},[s._v("$createAaBb")]),s._v("\n"),e("ul",[e("li",[e("code",{pre:!0},[s._v("{Object} config")]),s._v(" It will be passed to the component as its props except the events in "),e("code",{pre:!0},[s._v("events")]),s._v("(It will transform by default, eg: If "),e("code",{pre:!0},[s._v("events")]),s._v(" has value "),e("code",{pre:!0},[s._v("['click']")]),s._v(", then the prop "),e("code",{pre:!0},[s._v("onClick")]),s._v(" will be treated as component's event and not component's props).")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Function} [renderFn]")]),s._v(" Optional, used to generate the VNode child node in the slot scene in general.")]),s._v(" "),e("li",[e("code",{pre:!0},[s._v("{Boolean} [single]")]),s._v(" Optional, whether the instantiated component is a singleton or not. If two parameters are provided and the "),e("code",{pre:!0},[s._v("renderFn")]),s._v("'s type is not function, then the "),e("code",{pre:!0},[s._v("single")]),s._v(" value is the sencond parameter's value.")])])]),s._v(" "),e("li",[s._v("The return of the method "),e("code",{pre:!0},[s._v("instance")]),s._v(" is a instantiated Vue component,and the "),e("code",{pre:!0},[s._v("remove")]),s._v(" method will be "),e("strong",[s._v("attached")]),s._v(" to this instance.You can invoke the "),e("code",{pre:!0},[s._v("remove")]),s._v(" method to destroy the component and detach the component's content from "),e("code",{pre:!0},[s._v("body")]),s._v(" element.")])])]),s._v(" "),e("li",[e("p",[s._v("Example:")]),s._v(" "),e("p",[s._v("First we create Hello.vue component:")]),s._v(" "),e("pre",{pre:!0},[e("code",{attrs:{"v-pre":"",class:"language-html"}},[e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("@click")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"clickHandler"')]),s._v(">")]),s._v("\n {{content}}\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"other"')]),s._v(">")]),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("slot")]),s._v(">")]),s._v("\n "),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n"),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("template")]),s._v(">")]),s._v("\n\n"),e("span",{attrs:{class:"hljs-tag"}},[s._v("<"),e("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(" "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v("="),e("span",{attrs:{class:"hljs-string"}},[s._v('"text/ecmascript-6"')]),s._v(">")]),e("span",{attrs:{class:"javascript"}},[s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("name")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'hello'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("props")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("String")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("default")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'Hello'")]),s._v("\n }\n },\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n clickHandler(e) {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$emit("),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", e)\n }\n }\n }\n")]),e("span",{attrs:{class:"hljs-tag"}},[s._v("</"),e("span",{attrs:{class:"hljs-name"}},[s._v("script")]),s._v(">")]),s._v("\n")])]),s._v(" "),e("p",[s._v("Then we make Hello.vue to an API style component by calling the "),e("code",{pre:!0},[s._v("createAPI")]),s._v(" method.")]),s._v(" "),e("pre",{pre:!0},[e("code",{attrs:{"v-pre":"",class:"language-js"}},[s._v(" "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Hello "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'./Hello.vue'")]),s._v("\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// import Style to load the base style")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* eslint-disable no-unused-vars */")]),s._v("\n Style,\n Dialog,\n createAPI\n } "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'cube-ui'")]),s._v("\n\n Vue.use(Dialog)\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// create this.$createHello API")]),s._v("\n createAPI(Vue, Hello, ["),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v("], "),e("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v(")\n\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// init Vue")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("el")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'#app'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("render")]),s._v(": "),e("span",{attrs:{class:"hljs-function"}},[e("span",{attrs:{class:"hljs-keyword"}},[s._v("function")]),s._v(" ("),e("span",{attrs:{class:"hljs-params"}},[s._v("h")]),s._v(") ")]),s._v("{\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" h("),e("span",{attrs:{class:"hljs-string"}},[s._v("'button'")]),s._v(", {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("on")]),s._v(": {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("click")]),s._v(": "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".showHello\n }\n }, ["),e("span",{attrs:{class:"hljs-string"}},[s._v("'Show Hello'")]),s._v("])\n },\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n showHello() {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* The first parameter of `$createHello` will be passed to the component as its props except the events in `events`(It will transform by default, eg: If `events` has value `['click']`, then the prop `onClick` will be treated as component's event and not component's props) */")]),s._v("\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" instance = "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createHello({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'My Hello Content'")]),s._v(",\n onClick(e) {\n "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),e("span",{attrs:{class:"hljs-string"}},[s._v("'Hello component clicked.'")]),s._v(")\n }\n }, "),e("span",{attrs:{class:"hljs-comment"}},[s._v("/* renderFn */")]),s._v(" (createElement) => {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" [\n createElement("),e("span",{attrs:{class:"hljs-string"}},[s._v("'p'")]),s._v(", {\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("slot")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'other'")]),s._v("\n }, "),e("span",{attrs:{class:"hljs-string"}},[s._v("'other content'")]),s._v(")\n ]\n })\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// Also, the event hanlder can be registered by instance's `$on` method")]),s._v("\n instance.$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'click'")]),s._v(", (e) => {\n "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" $dialog = "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createDialog({\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("content")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'click confirm to remove current instance'")]),s._v(",\n "),e("span",{attrs:{class:"hljs-attr"}},[s._v("icon")]),s._v(": "),e("span",{attrs:{class:"hljs-string"}},[s._v("'cubeic-alert'")]),s._v("\n })\n $dialog.show()\n\n $dialog.$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'confirm'")]),s._v(", () => {\n "),e("span",{attrs:{class:"hljs-comment"}},[s._v("// remove instance")]),s._v("\n instance.remove()\n }).$on("),e("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(", () => {\n "),e("span",{attrs:{class:"hljs-built_in"}},[s._v("console")]),s._v(".log("),e("span",{attrs:{class:"hljs-string"}},[s._v("'cancel'")]),s._v(")\n })\n })\n }\n }\n })\n")])]),s._v(" "),e("p",[s._v("In this example, we create a component "),e("code",{pre:!0},[s._v("Hello")]),s._v(" which needs to be invoked in api form and we invoke it in another component.The focus is what "),e("code",{pre:!0},[s._v("showHello()")]),s._v(" does: invoking method "),e("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" to instantiate "),e("code",{pre:!0},[s._v("Hello")]),s._v(".")])])])},function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("p",[s._v("In vue component, you could call by "),e("code",{pre:!0},[s._v("this.$createHello(config, renderFn)")]),s._v(" because the "),e("code",{pre:!0},[s._v("this")]),s._v(" is just a vue instance. But in general JS files, you need to call "),e("code",{pre:!0},[s._v("$createHello")]),s._v(" method by "),e("code",{pre:!0},[s._v("Vue.prototype")]),s._v(" or create a vue instance. As shown below:")])},function(){var s=this,t=s.$createElement,e=s._self._c||t;return e("pre",{pre:!0},[e("code",{attrs:{"v-pre":"",class:"language-js"}},[e("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" Vue "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),e("span",{attrs:{class:"hljs-string"}},[s._v("'vue'")]),s._v("\n\nVue.prototype.$createHello(config, renderFn)\n\n"),e("span",{attrs:{class:"hljs-comment"}},[s._v("// or")]),s._v("\n"),e("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" vm = "),e("span",{attrs:{class:"hljs-keyword"}},[s._v("new")]),s._v(" Vue()\nvm.$createHello(config, renderFn)\n")])])}]}}});
\ No newline at end of file
!function(e){function c(a){if(f[a])return f[a].exports;var d=f[a]={i:a,l:!1,exports:{}};return e[a].call(d.exports,d,d.exports,c),d.l=!0,d.exports}var a=window.webpackJsonp;window.webpackJsonp=function(f,n,r){for(var b,t,o,u=0,i=[];u<f.length;u++)t=f[u],d[t]&&i.push(d[t][0]),d[t]=0;for(b in n)Object.prototype.hasOwnProperty.call(n,b)&&(e[b]=n[b]);for(a&&a(f,n,r);i.length;)i.shift()();if(r)for(u=0;u<r.length;u++)o=c(c.s=r[u]);return o};var f={},d={54:0};c.e=function(e){function a(){b.onerror=b.onload=null,clearTimeout(t);var c=d[e];0!==c&&(c&&c[1](new Error("Loading chunk "+e+" failed.")),d[e]=void 0)}var f=d[e];if(0===f)return new Promise(function(e){e()});if(f)return f[2];var n=new Promise(function(c,a){f=d[e]=[c,a]});f[2]=n;var r=document.getElementsByTagName("head")[0],b=document.createElement("script");b.type="text/javascript",b.charset="utf-8",b.async=!0,b.timeout=12e4,c.nc&&b.setAttribute("nonce",c.nc),b.src=c.p+"js/"+e+"."+{0:"54eb0fc561a0cdd92a38",1:"c6f7fa050d184e0659fa",2:"3143ef56ad7d78d9c12e",3:"5a951463b26edec51fe0",4:"4ada51adfd5f97a21540",5:"3f4298e66f337f7d8d07",6:"7897570f4a91d03f8177",7:"727504cecf286a177af0",8:"13af490846c5d8ecbc4c",9:"66c5c5b5307830e7e8de",10:"da7b87cec4b076cdc34d",11:"d72fc075616fed1755d9",12:"e346c8c181c29fdaf8ef",13:"dcb0d2b353c74abed11f",14:"a56514ce8b227dadd96f",15:"00e74fc2be52c9b1089c",16:"3cb45f74a396c0b221fb",17:"b50e1c2cdfd11519b9c8",18:"6e7084b71912ccee516d",19:"08525f626cc7c8321b83",20:"c9ec755dac9171c67a12",21:"3677344dff964cef544e",22:"53179e7d9fcb48268a27",23:"e4d9081b86adc852feeb",24:"af7ec837d33f75e85fec",25:"75f8b418a165704354e6",26:"08372c9a2cb5ef5b7a67",27:"67fc1db41dfb795782a3",28:"f8bb82c51fd1faf15e64",29:"83568677575e5f4d4757",30:"7853cfc1c5cd3dc73d78",31:"4f7258a42c9358765fe4",32:"c07beadc88c15a70ed9a",33:"e20623676664b2d62435",34:"1e05abd53d4fa6d88b92",35:"058f4534ba01c0bcb581",36:"ee1fe8efde6d6ee04155",37:"a587090d2b7d6c1bea20",38:"8a88bbb7015ef4e054ab",39:"af85018640cba6dd6a84",40:"9a89f8a1d0a2533d38a9",41:"88dc47e31e6f9b0f32f0",42:"e36f5dcb4a4d791fd960",43:"210b154adc2aade18ede",44:"729598390ad6ccdcb168",45:"c5a6aed97d82e988760b",46:"125158cd69e8a9477b9a",47:"a5b1407372d048eaf26a",48:"3e7a6ed3b42f03598da3",49:"c4737cc5244368760f5f",50:"855b6588920a1949beb7",51:"baa03f6ea54aa840a7cc",52:"4bef0c72c513e604f246",53:"30b2fe9216fb3d5b9491"}[e]+".js";var t=setTimeout(a,12e4);return b.onerror=b.onload=a,r.appendChild(b),n},c.m=e,c.c=f,c.d=function(e,a,f){c.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:f})},c.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(a,"a",a),a},c.o=function(e,c){return Object.prototype.hasOwnProperty.call(e,c)},c.p="/cube-ui/",c.oe=function(e){throw console.error(e),e}}([]);
\ No newline at end of file
!function(e){function c(a){if(f[a])return f[a].exports;var d=f[a]={i:a,l:!1,exports:{}};return e[a].call(d.exports,d,d.exports,c),d.l=!0,d.exports}var a=window.webpackJsonp;window.webpackJsonp=function(f,n,r){for(var b,t,o,u=0,i=[];u<f.length;u++)t=f[u],d[t]&&i.push(d[t][0]),d[t]=0;for(b in n)Object.prototype.hasOwnProperty.call(n,b)&&(e[b]=n[b]);for(a&&a(f,n,r);i.length;)i.shift()();if(r)for(u=0;u<r.length;u++)o=c(c.s=r[u]);return o};var f={},d={54:0};c.e=function(e){function a(){b.onerror=b.onload=null,clearTimeout(t);var c=d[e];0!==c&&(c&&c[1](new Error("Loading chunk "+e+" failed.")),d[e]=void 0)}var f=d[e];if(0===f)return new Promise(function(e){e()});if(f)return f[2];var n=new Promise(function(c,a){f=d[e]=[c,a]});f[2]=n;var r=document.getElementsByTagName("head")[0],b=document.createElement("script");b.type="text/javascript",b.charset="utf-8",b.async=!0,b.timeout=12e4,c.nc&&b.setAttribute("nonce",c.nc),b.src=c.p+"js/"+e+"."+{0:"54eb0fc561a0cdd92a38",1:"c6f7fa050d184e0659fa",2:"3143ef56ad7d78d9c12e",3:"5a951463b26edec51fe0",4:"4ada51adfd5f97a21540",5:"3f4298e66f337f7d8d07",6:"7897570f4a91d03f8177",7:"727504cecf286a177af0",8:"13af490846c5d8ecbc4c",9:"66c5c5b5307830e7e8de",10:"da7b87cec4b076cdc34d",11:"d72fc075616fed1755d9",12:"e346c8c181c29fdaf8ef",13:"dcb0d2b353c74abed11f",14:"a56514ce8b227dadd96f",15:"00e74fc2be52c9b1089c",16:"3cb45f74a396c0b221fb",17:"b50e1c2cdfd11519b9c8",18:"6e7084b71912ccee516d",19:"08525f626cc7c8321b83",20:"5ce8292a7803ab35eaf6",21:"3677344dff964cef544e",22:"53179e7d9fcb48268a27",23:"e4d9081b86adc852feeb",24:"af7ec837d33f75e85fec",25:"75f8b418a165704354e6",26:"08372c9a2cb5ef5b7a67",27:"67fc1db41dfb795782a3",28:"f8bb82c51fd1faf15e64",29:"83568677575e5f4d4757",30:"7853cfc1c5cd3dc73d78",31:"4f7258a42c9358765fe4",32:"c07beadc88c15a70ed9a",33:"e20623676664b2d62435",34:"1e05abd53d4fa6d88b92",35:"058f4534ba01c0bcb581",36:"ee1fe8efde6d6ee04155",37:"a587090d2b7d6c1bea20",38:"8a88bbb7015ef4e054ab",39:"af85018640cba6dd6a84",40:"9a89f8a1d0a2533d38a9",41:"88dc47e31e6f9b0f32f0",42:"e36f5dcb4a4d791fd960",43:"210b154adc2aade18ede",44:"729598390ad6ccdcb168",45:"f81a7b71ea74ff86a71d",46:"125158cd69e8a9477b9a",47:"a5b1407372d048eaf26a",48:"3e7a6ed3b42f03598da3",49:"c4737cc5244368760f5f",50:"855b6588920a1949beb7",51:"baa03f6ea54aa840a7cc",52:"4bef0c72c513e604f246",53:"30b2fe9216fb3d5b9491"}[e]+".js";var t=setTimeout(a,12e4);return b.onerror=b.onload=a,r.appendChild(b),n},c.m=e,c.c=f,c.d=function(e,a,f){c.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:f})},c.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(a,"a",a),a},c.o=function(e,c){return Object.prototype.hasOwnProperty.call(e,c)},c.p="/cube-ui/",c.oe=function(e){throw console.error(e),e}}([]);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册