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博客

相关推荐
睡不着的可乐14 小时前
createElement → VNode 是怎么创建的
前端·javascript·vue.js
光影少年14 小时前
前端css如何实现水平垂直居中?
前端·javascript·css
C澒15 小时前
SLDS 自营物流系统:Pickup 揽收全流程
前端·架构·系统架构·教育电商·交通物流
摸鱼的春哥15 小时前
把白领吓破防的2028预言,究竟讲了什么?
前端·javascript·后端
infiniteWei15 小时前
SKILL.md 触发机制与设计规范:避免“写了不触发”
java·前端·设计规范
慧一居士15 小时前
SVG图片介绍和使用
前端
Rysxt_15 小时前
Uniapp全局配置教程
前端·uniapp
阿珊和她的猫15 小时前
深入理解与使用 Cookie:Web 开发中的关键机制
前端·状态模式
用户5474875962215 小时前
webpack代码分割
前端