如何解决如何在 vue2 渲染函数中将一些值绑定到 this.$slots.default?
众所周知,我们可以使用 this.$slots.default 来创建一个插槽。
如果我们使用 template ,我们可以像这样向槽发送一个值:
<slot name="xiaoming" value="gugugu"></slot>
但是如何在 vue2 的渲染函数中向 this.$slots.default 发送值?
解决方法
如果只想将值传递给渲染组件中的插槽,您可以这样做:
Vue.component('wrapper',{
render(h) {
return h('div',[
this.$scopedSlots.default({
test: 'works!'
})
])
}
})
new Vue({
el: '#app',data: {
message: 'Hello Vue.js!'
}
})
就在外面用
<div id="app">
<p>{{ message }}</p>
<wrapper>
<template v-slot="props">
<p>{{props.test}}</p>
</template>
</wrapper>
</div>
继续...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。