vue2-render:vue2项目使用render / 基础使用

一、本文内容

本文内容记录render常用的一些属性和方法的配置,以作参考

复制代码
export default {  
  data() {
    return {  
      modelValue: '',
      key: 0,
    };  
  },  
  render(h) {  
    return h('div', [  
      h('input', {
        class: 'input',
        attrs: { 
          type: 'text'  
        },  
        key: this.key,
        props: {  
          value: this.modelValue,
          showPassword: item.password || false,
        },
        style: { display: 'hidden' ? 'none' : ''},
        on: {  
          input: (e) => {  
            this.modelValue = e.target.value;  
          }  
        },  
        ref: 'myInput'  
      }),  
      h('p', `输入的内容是: ${this.modelValue}`)  
    ]);  
  }  
};

二、插槽的使用

复制代码
import Vue from 'vue';  
import { h } from 'vue/dist/vue.esm.js'; // 确保从正确的路径导入 h 函数  
import { ElCascader, ElTooltip } from 'element-ui'; // 假设你已经安装了 element-ui  
  
export default {  
  components: {  
    ElCascader,  
    ElTooltip  
  },  
  data() {  
    return {  
      value: [],  
      list: [  
        // ... 你的选项列表  
      ]  
    };  
  },  
  render(createElement) {  
    const scopedSlot = scope => {  
      const { data } = scope;  
      return h('el-tooltip', {  
        props: {  
          disabled: data.label.length < 12,  
          effect: 'dark',  
          content: data.label,  
          placement: 'right'  
        },  
        class: 'item'  
      }, [  
        h('span', [data.label])  
      ]);  
    };  
  
    return h('el-cascader', {  
      props: {  
        value: this.value,  
        options: this.list  
      },  
      scopedSlots: {  
        default: scopedSlot  
      }  
    });  
  }  
};

参考链接

element里面的el-cascader组件宽度限制_el-cascader 宽度-CSDN博客

相关推荐
小二·3 小时前
Pinia 完全指南:用 TypeScript 构建可维护、可测试、可持久化的 Vue 3 状态管理
javascript·vue.js·typescript
bug总结3 小时前
Vue3 实现后台管理系统跳转大屏自动登录功能
前端·javascript·vue.js
用户47949283569153 小时前
同事一个比喻,让我搞懂了Docker和k8s的核心概念
前端·后端
烛阴3 小时前
C# 正则表达式(5):前瞻/后顾(Lookaround)——零宽断言做“条件校验”和“精确提取”
前端·正则表达式·c#
C_心欲无痕3 小时前
浏览器缓存: IndexDB
前端·数据库·缓存·oracle
郑州光合科技余经理4 小时前
技术架构:上门服务APP海外版源码部署
java·大数据·开发语言·前端·架构·uni-app·php
GIS之路4 小时前
GDAL 实现数据属性查询
前端
PBitW5 小时前
2025,菜鸟的「Vibe Coding」时刻
前端·年终总结
mwq301235 小时前
不再混淆:导数 (Derivative) 与微分 (Differential) 的本质对决
前端
小二·6 小时前
Vue 3 组件通信全方案详解:Props/Emit、provide/inject、事件总线替代与组合式函数封装
前端·javascript·vue.js