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

相关推荐
Kakarotto1 天前
Canvas 直线点击事件处理优化
javascript·vue.js·canvas
顺遂1 天前
基于Rokid CXR-M SDK的引导式作业辅导系统设计与实现
前端
代码搬运媛1 天前
Generator 迭代器协议 & co 库底层原理+实战
前端
前端拿破轮1 天前
从0到1搭建个人网站(三):用 Cloudflare R2 + PicGo 搭建高速图床
前端·后端·面试
功能啥都不会1 天前
PM2 使用指南 - 踩坑记录
前端
HelloReader1 天前
React 中 useState、useEffect、useRef 的区别与使用场景详解,终于有人讲明白了
前端
兆子龙1 天前
CSS 里的「if」:@media、@supports 与即将到来的 @when/@else
前端
踩着两条虫1 天前
AI 智能体如何重构开发工作流
前端·人工智能·低代码
代码老中医1 天前
逃离"Div汤":2026年,当AI写了75%的代码,前端开发者还剩什么?
前端
进击的尘埃1 天前
Playwright Component Testing 拆到底:组件怎么挂上去的,快照怎么在 CI 里不翻车
javascript