【问题标题】:VueJS render component instancesVueJS 渲染组件实例
【发布时间】:2021-10-26 03:38:35
【问题描述】:

我有一个由组件实例动态填充的子组件列表

data: function () {
      return {
        child_components: []
    }
}

我希望它们在列表更改时在模板中呈现,这不起作用:

<li v-for="c in child_components">
    {{c.$el}}
</li>

是否可以渲染实际的组件实例?因为在组件模板中有更改其数据的输入,我想从 child_components 列表中访问该数据。

谢谢

【问题讨论】:

  • 我需要更深入地了解您的代码来判断您想要实现的目标。
  • 这是 XY 问题。您需要将状态提升到父组件,因此它恰好在需要访问的位置。
  • 更明确一些,以便我们了解真正的问题。

标签: javascript vue.js vue-component


【解决方案1】:

我认为你需要一些东西。 child_components 是对象的键,所以不能这样使用。

data: {
  child_components: function () {
      return [
         { el: 'example' },
         { el2: 'example2' },
      ];
  }
}

<li v-for="c in child_components">
    {{c.el}}
</li>

【讨论】:

    猜你喜欢
    • 2018-12-25
    • 2017-01-01
    • 2019-12-09
    • 1970-01-01
    • 2019-04-27
    • 2019-10-03
    • 2018-06-27
    • 2020-04-02
    • 1970-01-01
    相关资源
    最近更新 更多