【问题标题】:Vue's render createElement gives error when passed a regular Vue fileVue渲染器createElement在传递常规Vue文件时出错
【发布时间】:2019-09-19 15:19:53
【问题描述】:

所以我创建了一个带有渲染函数的 Vue 文件,该函数应该循环遍历 ID 并根据这些创建组件。

特别是在我的渲染函数中,我使用了createElement,我将三个参数传递给它:

  1. 一个 Vue 组件(来自 JS 文件)
  2. 一个配置对象
  3. Vue 组件(来自 Vue 文件)

这是 3. 这给了我这个错误:

挂载组件失败:未定义模板或渲染函数。

这个 Vue 文件没有渲染功能,但它确实有一个 template,所以我很困惑为什么会发生这个错误。

在下面的代码中[createElement([dialogs[id]])] 是给出错误的部分:

import { QDialog } from 'quasar'
import Signin from './Signin.vue'
import Signout from './Signout.vue'

const dialogs = {
  Signin,
  Signout
}

function createDialogNode (id, createElement, parent) {
  return createElement(QDialog, {
    props: {
      value: parent.toggles[id]
    },
    on: {
      input: function (newState) {
        parent.toggles[id] = newState
      }
    }
  }, [createElement([dialogs[id]])])
}

// further down I use `createDialogNode` inside the render function and loop over the props inside `dialogs`.

所以在上面的代码中,您会看到我有一个带有导入组件的对象dialogs。这些组件是常规的 Vue 文件。

我想在createElement 中将它们作为第三个参数传递给在我上面的函数中返回的另一个createElement

【问题讨论】:

    标签: vue.js vuejs2 render createelement


    【解决方案1】:

    您不能将数组作为第一个参数传递给 createElement

    试试这个:

    createElement(dialogs[id])
    

    【讨论】:

    • 非常感谢十年月!! (非常感谢您的支持?)
    猜你喜欢
    • 2021-03-10
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 2019-05-02
    • 2021-08-07
    • 2018-10-07
    • 2016-12-16
    相关资源
    最近更新 更多