当前位置: 首页 > news >正文

vue el-button 封装及使用

使用了 Element UI 中的 el-button 组件,并对其进行了封装和定制。

创建组件index.vue (src/common-ui/button/index.vue)
<template><el-buttonclass="h-button":type="type":icon="hIcon":disabled="disabled"@click="$emit('click')":loading="loading"><span class="h-button-caption">{{ hCaption }}</span></el-button>
</template><script>export default {name: 'HButton',props: {action: {type: String,validator (value) {return (['add','edit','delete','export','print','return','entry','addNoti','download','appointRow'].indexOf(value) !== -1)},defautl: 'add'},type: {type: String,default: 'primary'},btnClass: String,caption: String,icon: String,disabled: {type: Boolean,default: false},loading: {type: Boolean,default: false}},data () {return {hCaption: '',hIcon: ''}},created () {switch (this.action) {case 'add':this.hCaption = '新增'this.hIcon = ''breakcase 'edit':this.hCaption = '编辑'this.hIcon = ''breakcase 'delete':this.hCaption = '删除'this.hIcon = ''breakcase 'export':this.hCaption = '导出'this.hIcon = ''breakdefault:this.hCaption = this.captionthis.hIcon = this.iconbreak}if (this.caption) {this.hCaption = this.caption}},computed: {hasImg () {return (this.action === 'export' ||this.action === 'add' ||this.action === 'edit' ||this.action === 'delete' ||this.action === 'print' ||this.action === 'return' ||this.action === 'entry' ||this.action === 'addNoti')},isLang () {return (this.hCaption &&(this.hCaption.length > 4 ||(this.hCaption.length > 3 && (this.hIcon || this.hasImg))))}},watch: {btnClass: {handler (val) {},immediate: true}}}
</script>
页面引入
  • 在需要使用addressCascader组件的地方,通过import语句引入组件注册并使用

<template><div><templatev-for="({ caption, display, permissionKey, icon, disabled, callback, action, type, btnClass, loading },index) in buttonList"><h-button v-if="getButtonDisplay(display)":key="action ? index + action : index":action="action":btnClass="btnClass":caption="caption":icon="icon":disabled="disabled":type="type || 'primary'":loading="loading"@click="callback"v-permission="permissionKey"></h-button></template></div>
</template>
<script>import HButton from "@/common-ui/button/index";export default {components: {HButton},data() {return {dataSource: [],selectedValue: ''}},computed:{buttonList() {return [{caption: "返回",type: "warning",callback: this.back,btnClass: "warningButton"},{caption: "确认",type: "primary",callback: this.submit,btnClass: "primaryButton"}]}},methods: {back() {},submit() {}}// ...}
</script>

确保你已经安装了Vue.js和Element UI,并在项目中引入它们。

http://www.lryc.cn/news/251510.html

相关文章:

  • QT之QMediaPlayer的用法
  • TCP_报文格式解读
  • C语言面试之旅:掌握基础,探索深度(面试实战之c语言关键词下篇)
  • Java学习第十三天
  • 【Delphi】实现彩色日志显示框(TRichEdit Helper)
  • Elasticsearch 优化查询中获取字段内容的方式,性能提升5倍!
  • 图像批量设计软件Retrobatch Pro mac中文版功能特色
  • python第3天之函数
  • SQL Server 数据库,为products表添加数据
  • C语言结构体详解(二)(能看懂文字就能明白系列)文章很长,慢慢品尝
  • WPF不使用AllowsTransparency实现高性能透明背景异形窗体
  • 唯创知音WT2605C语音芯片MP3音频IC:轻松实现指令随机播放与无缝循环播放等功能
  • uniapp+微信小程序监听返回事件
  • Python函数的高级用法
  • excel单元格内换行按什么快捷键
  • docker容器内部文件挂载主机
  • python 实现一个简单的计算器
  • 前端对浏览器的理解
  • Linux(openssl):X509_verify通过ca证书的public key验证证书的签名
  • 全面的.NET微信网页开发之JS-SDK使用步骤、配置信息和接口请求签名生成详解
  • 深入了解汉字转拼音转换工具:原理与应用
  • 沈阳师范大学期末考试复习pta循环数组函数指针经典编程题汇总+代码分析
  • 【面试攻略】Oracle中blob和clob的区别及查询修改方法
  • An illegal reflective access operation has occurred问题记录
  • 抓取检测(Grasp Dection)
  • 人工智能学习4(特征选择)
  • vue中keep-alive的使用
  • 2023年第十二届数学建模国际赛小美赛B题工业表面缺陷检测求解分析
  • 2023全球数字贸易大赛-web3,区块链,诺威信,浪潮云,微众区块链,福建中科星泰,瓴羊区块链,联想-元宇宙,硅基智能-
  • 计算机网络一:TCP/IP基础概念和常见面试题