vue.js - 将一个也需要插槽属性的组件传递给插槽
问题描述
我如何测试带有插槽的组件,例如轮播内部有一个插槽组件,而滑块内部有一个插槽组件。
这不支持该功能。
也许我必须使用 e2e 测试?
请告诉我如何做到这一点。谢谢你。
// This is how i use
<carousel>
<slide>
<div></div>
</slide>
</carousel>
// Carousel component
<carousel>
<slot></slot>
</carousel>
// Slide component
<slide>
<slot></slot>
</slide>
解决方案
你必须像这样编辑 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}"
到组件中。
推荐阅读
- reactjs - Prevent Backspace to avoid erasing of initial value in text box in React
- r - 如果列表中有值,则替换字段值
- git - 如果我在分叉的存储库中打开一个问题,修复它并拉请求提交,原始 Github 存储库是否也有问题?
- c++ - 为什么我的归并排序最后放了一个随机的 4?
- c++ - 为什么我不能继续使用 std::cin 向同一个变量输入其他值?
- reactjs - 为导入的节点模块提供 React Context
- java - 当 JComboBox 项目更改时删除另一个 JComponent
- ruby-on-rails - 将数组移动到 Rails ActiveRecord 表中的方法
- javascript - 如何将所有页面添加到 cache.addAll
- python - 在括号之间找到一些东西