render 函数中使用组件等

js 复制代码
 		 render: (h) => {
 		 	// 方案1:
            return h('el-switch', {
              props: {
                value: true
              },
              on: {
                change: (e) => {
                  console.log(e, '改变')
                }
              }
            })
          // 方案二:
           const onChange = (e) => {
             console.log(e, '改变')
           }
           return (
             <el-switch value={true} onChange={onChange}>
             </el-switch>
          )

由于 render 函数中没有 v-bind、v-on 等内置指令,因此我们将如何使用呢?

js 复制代码
render () {
  const props = {
    ...this.$attrs,
    ...this.$props,
  }
  const on = {
    this.$listeners,
  }
  return (
    <a-table
      {...{ props, scopedSlots: { ...this.$scopedSlots } }}
      {...{ on }}
    >
      Object.keys(this.slots).map(name => (<template slot={name}>{this.$slots[name]}</template>))
    </a-table>
  )
}

$scopedSlots用来访问作用域插槽。对于包括 默认 slot 在内的每一个插槽,该对象都包含一个返回相应 VNode 的函数。vm.$scopedSlots 在使用渲染函数开发一个组件时特别有用。

js 复制代码
render () {
  return (
    <a-table
      onChange={this.loadData}
      {...{ scopedSlots: ...this.$scopedSlots }}
    />
  )
}

其他相关博客

相关推荐
万行1 天前
企业级前后端认证方式
前端·windows
2501_948120151 天前
基于Vue 3的可视化大屏系统设计
前端·javascript·vue.js
+VX:Fegn08951 天前
计算机毕业设计|基于springboot + vue酒店预订系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
Jinuss1 天前
源码分析之React中createFiberRoot方法创建Fiber根节点
前端·javascript·react.js
Jinuss1 天前
源码分析之React中ReactDOMRoot实现
前端·javascript·react.js
摘星编程1 天前
React Native鸿蒙版:React Query无限滚动
javascript·react native·react.js
web守墓人1 天前
【前端】vue3的指令
前端
想起你的日子1 天前
EFCore之Code First
前端·.netcore
框架图1 天前
Html语法
前端·html
深耕AI1 天前
【wordpress系列教程】07 网站迁移与备份
运维·服务器·前端·数据库