|
@@ -48,6 +48,16 @@ export function createInstance(platform, options = {}) {
|
|
|
return instance
|
|
|
}
|
|
|
|
|
|
+export function renderInstance(instance, el) {
|
|
|
+ // 将组件的 DOM 添加到页面
|
|
|
+ if (isDOMElement(el)) {
|
|
|
+ el.appendChild(instance.$el)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ document.querySelector(el).appendChild(instance.$el)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export async function doLeave(options = {}) {
|
|
|
const {
|
|
|
source, // 必传
|
|
@@ -80,11 +90,32 @@ export async function doLeave(options = {}) {
|
|
|
|
|
|
instance.updateVisible(true)
|
|
|
// 将组件的 DOM 添加到页面
|
|
|
- if (isDOMElement(el)) {
|
|
|
- el.appendChild(instance.$el)
|
|
|
- }
|
|
|
- else {
|
|
|
- document.querySelector(el).appendChild(instance.$el)
|
|
|
+ renderInstance(instance, el)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function renderComponent(el, componentId, options = {}) {
|
|
|
+ const { props } = options
|
|
|
+
|
|
|
+ if (!el) {
|
|
|
+ return console.error('目标dom选择器不能为空')
|
|
|
+ }
|
|
|
+ if (!componentId) {
|
|
|
+ return console.error('componentId不能为空')
|
|
|
+ }
|
|
|
+
|
|
|
+ const instance = createInstance(componentId)
|
|
|
+ if (instance) {
|
|
|
+ // props赋值
|
|
|
+ if (props) {
|
|
|
+ for (const key in props) {
|
|
|
+ if (props[key]) {
|
|
|
+ instance[key] = props[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 将组件的 DOM 添加到页面
|
|
|
+ renderInstance(instance, el)
|
|
|
}
|
|
|
}
|