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

相关推荐
葬送的代码人生几秒前
用一句 Prompt 十分钟搓出完整应用
前端·html·ai编程
干中学_20264 分钟前
vue3 画布编辑器「平移」天坑?只需 5 行代码,完美优雅复刻大厂体验!
javascript
ShiJiuD6668889999 分钟前
大事件板块三
前端·bootstrap·html
JavaAgent架构师21 分钟前
前端AI工程化(五):AI对话状态管理
前端·人工智能
ricardo197334 分钟前
一张图搞懂 HTTP 缓存:强缓存、协商缓存与最佳 Cache-Control 配置
前端
程序员码歌36 分钟前
别再让 AI 自由发挥了:OpenSpec 才是团队协作不跑偏的关键
android·前端·人工智能
用户114818678948442 分钟前
Vue 开发者快速上手 Flutter(二)
前端
用户11481867894841 小时前
Vue 开发者快速上手 Flutter(三)
前端
JavaAgent架构师1 小时前
前端AI工程化(六):Function Calling与RAG前端实践
前端·人工智能
用户11481867894841 小时前
Vue 开发者快速上手 Flutter(一)
前端