【问题标题】:VueJs - Nesting custom componentsVueJs - 嵌套自定义组件
【发布时间】:2017-08-10 08:14:17
【问题描述】:

我有一些问题。我将创建几个组件,并尝试嵌套它们。所以我有一个例子

<body>
    <div class="app">
        <image-slider>
            <slide image="image01.jpg"></slide-image>
            <slide image="image02.jpg"></slide-image>
            <slide image="image03.jpg"></slide-image>
        </image-slider>
    </div>
</body>

这是静态 HTML,此内容不是用 VueJS 添加的。
我试图创建它们,但我不能。


你有什么想法吗?
感谢您的帮助。

【问题讨论】:

  • 你的javascript代码是什么?
  • 我没有JS代码,因为我做不到

标签: nested components vue.js


【解决方案1】:

如果image-slider和slide都是自定义组件,那么可以先创建slide组件,后创建image-slider,从image-slider引用slide,这里有个jsFiddledemo

 <image-slider :images="['http://placehold.it/350x150','http://placehold.it/200x100']">
</image-slider>

 // use slide only

 <slide image="http://placehold.it/200x100"></slide>

【讨论】:

  • 所以无法创建自定义组件?
  • 为什么不呢?该示例有两个自定义组件,即:slide 和 image-slider
  • 但我想创建,这看起来像我的例子。
猜你喜欢
  • 2016-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-26
  • 2017-04-28
  • 1970-01-01
相关资源
最近更新 更多