我想执行以下操作,但使用 Vue 2 的渲染功能
<template>
<imported-component>
<template v-slot:default="{ importedFunction }">
<button @click="importedFunction">Do something</button>
</template>
</import-component>
</template>
最佳答案
- 使用
scopedSlots
作为插槽 - 使用插槽名称(“默认”)加上插槽属性的函数参数
- 使用
on
作为事件处理程序
render(h) {
return h('imported-component', {
scopedSlots: {
default(slotProps) {
return h('button', {
on: {
click: slotProps.importedFunction
}
}, 'Do something')
}
}
});
}
关于javascript - 如何在 Vue 2 渲染函数中使用插槽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65662621/