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

相关推荐
p***h64333 分钟前
JavaScript在Node.js中的异步编程
开发语言·javascript·node.js
N***73851 小时前
Vue网络编程详解
前端·javascript·vue.js
e***71671 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
程序猿小蒜1 小时前
基于springboot的的学生干部管理系统开发与设计
java·前端·spring boot·后端·spring
银空飞羽1 小时前
让Trae CN SOLO自主发挥,看看能做出一个什么样的项目
前端·人工智能·trae
Eshine、2 小时前
解决前端项目中,浏览器无法正常加载带.gz名称的文件
前端·vue3·.gz·.gz名称的js文件无法被加载
q***38512 小时前
TypeScript 与后端开发Node.js
javascript·typescript·node.js
用户47949283569152 小时前
别再当 AI 的"人肉定位器"了:一个工具让 React 组件秒定位
前端·aigc·ai编程
Nan_Shu_6143 小时前
学习:Sass
javascript·学习·es6
WYiQIU3 小时前
面了一次字节前端岗,我才知道何为“造火箭”的极致!
前端·javascript·vue.js·react.js·面试