2

我想做以下事情,但使用 Vue 2 的渲染功能

<template>
  <imported-component>
    <template v-slot:default="{ importedFunction }">
       <button @click="importedFunction">Do something</button>
    </template>
  </import-component>
</template>
4

1 回答 1

1
  • 用于scopedSlots插槽
  • 使用插槽名称(“默认”)加上插槽道具的函数参数
  • 用于on事件处理程序
render(h) {
  return h('imported-component', {
    scopedSlots: {
      default(slotProps) {
        return h('button', {
          on: {
            click: slotProps.importedFunction
          }
        }, 'Do something')
      }
    }
  });
}
于 2021-01-11T07:54:18.517 回答