将需要插槽属性的组件传递给插槽

时间:2018-09-03 20:09:37

标签: vue.js vue-test-utils

例如,如何测试带有插槽的组件 轮播内部有一个插槽组件 滑块内部有一个插槽组件。

This不支持该功能。

也许我必须使用e2e测试?

请告诉我如何执行此操作。谢谢。

// This is how i use
<carousel>
  <slide>
    <div></div>
  </slide>
</carousel>

// Carousel component
<carousel>
  <slot></slot>
</carousel>

// Slide component
<slide>
  <slot></slot>
</slide>

1 个答案:

答案 0 :(得分:0)

您必须编辑this之类的vue原型

在main.js文件中

 Vue.prototype._b = (function (bind) {
  return function(data, tag, value, asProp, isSync) {
    if (value && value.$scopedSlots) {
      data.scopedSlots = value.$scopedSlots;
      delete value.$scopedSlots;
    }
    return bind.apply(this, arguments);
  };
})(Vue.prototype._b);

您只需要向组件添加v-bind="{$scopedSlots}"

相关问题