• 【Vue】Element开发笔记


    Element开发笔记

    前言

    【Vue】vue增加导航标签
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/134965353

    【Vue】Element开发笔记
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/133947977

    【Vue】vue,在Windows IIS平台部署
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/133859117

    【Vue】vue2与WebApi跨域CORS问题
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/133808959

    【Vue】nvm安装教程(解决npm下依赖包版本冲突)
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/132896207

    【Vue】vue开发环境搭建教程(详细)
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/132689006

    【Vue】全局日期格式化
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/135017332

    【Vue】elementUI表格,导出Excel
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/135018489

    【Vue】el-date-picker日期范围组件(本周、本月、上周)
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/135088143

    【前端】前后端通信方法与差异
    本文链接:https://blog.csdn.net/youcheng_ge/article/details/135153985


    官网 https://element.eleme.cn/#/zh-CN/component/upload

    其它项目网站 https://www.cnblogs.com/qq2806933146xiaobai/p/17180878.html
    在这里插入图片描述

    表格

    序号列添加

    
    
    • 1

    handleIndexCalc是计算分页中的ID,否则序号不准确。

    // 自动计算分页 Id
    handleIndexCalc(index) {
        return (
            (this.queryParams.pageIndex - 1) * this.queryParams.pageSize + index + 1
        )
    },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    选择列添加

    
    
    • 1

    注意:同时拥有 序号列、选择列,序号必须在 选择列前面

    表格高度统一,防止数据量少时,页脚上升

    表格设置height属性,根据浏览器界面大小自动计算高度,留页脚面板高度。

    <el-table ref="dataResult"
              v-loading="loading"
              :data="dataResult.dataSource"
              :height="tableHeight"
              :default-sort="{ prop: queryParams.orderby, order: queryParams.sort }"
              row-key="id"
              stripe
              border
              style="width: 100%;height=250"
              @sort-change="handleSortable">
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    Data:

    // 表格高度
    tableHeight: window.innerHeight - 280,
    
    • 1
    • 2

    项目实例:

          
          
            
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
                
              
            
            
          
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    Select选择器

    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    参数说明类型可选值默认值
    value / v-model绑定值boolean / string / number
    multiple是否多选booleanfalse
    disabled是否禁用booleanfalse
    value-key作为 value 唯一标识的键名,绑定值为对象类型时必填stringvalue
    size输入框尺寸stringmedium/small/mini
    clearable是否可以清空选项booleanfalse
    collapse-tags多选时是否将选中值按文字的形式展示booleanfalse
    multiple-limit多选时用户最多可以选择的项目数,为 0 则不限制number0
    nameselect input 的 name 属性string
    autocompleteselect input 的 autocomplete 属性stringoff
    auto-complete下个主版本弃用stringoff
    placeholder占位符string请选择
    filterable是否可搜索booleanfalse
    allow-create是否允许用户创建新条目,需配合 filterable 使用booleanfalse
    filter-method自定义搜索方法function
    remote是否为远程搜索booleanfalse
    remote-method远程搜索方法function
    loading是否正在从远程获取数据booleanfalse
    loading-text远程加载时显示的文字string加载中
    no-match-text搜索条件无匹配时显示的文字,也可以使用slot="empty"设置string无匹配数据
    no-data-text选项为空时显示的文字,也可以使用slot="empty"设置string无数据
    popper-classSelect 下拉框的类名string
    reserve-keyword多选且可搜索时,是否在选中一个选项后保留当前的搜索关键词booleanfalse
    default-first-option在输入框按下回车,选择第一个匹配项。需配合 filterableremote 使用boolean-false
    popper-append-to-body是否将弹出框插入至 body 元素。在弹出框的定位出现问题时,可将该属性设置为 falseboolean-true
    automatic-dropdown对于不可搜索的 Select,是否在输入框获得焦点后自动弹出选项菜单boolean-false

    项目实例

                  
                    
                  
    
    • 1
    • 2
    • 3
     // 搜索框-文档状态
     statusOptions: [],
              
     // 创建时 
     created() {
        getOption('SYSTEM_STATUS').then((response) => {
          this.statusOptions = response.data
        }),
        this.getList()
      },
          
     // 选择文档状态(搜索框)
     handleSelectSearchStatus(e) {
          this.queryParams.queryStatus = e
     },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    el-select 使用 multiple多选属性时,数据定义必须符合规范,并且返回的是 字符串数组,一开始需要定义好,否则数据无法显示。

                  
                    
                  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
        // 控件绑定的
        keyWordsList: [],
            
        /** 编辑按钮操作 */
        handleEdit(row) {
          this.reset()
          this.postForm = { ...row }
          this.keyWordsList =  row.keyWords.split(',') //数据库取出来是字符串,转数组
          this.bOpenForm = true
          this.title = '编辑文档'
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    dialog弹出框

    需要注意浅拷贝深拷贝 问题,row是Object对象类型,如果直接赋值,就变成了 浅拷贝,相当于我们的引用传递。

    //方法一
    this.form = JSON.parse(JSON.stringify(row));
    //方法二
    this.form = {...row}
    
    • 1
    • 2
    • 3
    • 4
    /** 新增按钮操作 */
    handleCreate() {
        this.reset()
        this.open = true
        this.title = '添加关键字'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      this.form = { ...row }
      this.open = true
      this.title = '修改关键字'
    },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    每次窗体打开,并不会清除上一次验证规则,需要手动调用clearValidate()方法清除,与C#一样。

      watch: {
        // 打开弹窗,清空上一次验证规则
        bOpenForm: {
          handler(newVal) {
            if (newVal) {
              this.$nextTick(() => {
                this.$refs['postForm'].clearValidate()
              })
            }
          },
        },
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    el-upload上传组件

    :action是执行上传动作的后台接口,el-button是触发上传的按钮。

    multiple 设置是否可以同时选中多个文件上传

    accept 设置限制上传文件的格式

    <el-upload 
        :action="uploadActionUrl"
        accept="image/jpeg,image/gif,image/png"
        :before-upload="onBeforeUpload"
        multiple
        :limit="3"
        :on-exceed="handleExceed">
        <el-button size="small" type="primary">点击上传el-button>
        <div slot="tip" class="el-upload__tip">请上传图片格式文件div>
    el-upload>
    ...
        onBeforeUpload(file)
        {
          const isIMAGE = file.type === 'image/jpeg'||'image/gif'||'image/png';
          const isLt1M = file.size / 1024 / 1024 < 1;
    
          if (!isIMAGE) {
            this.$message.error('上传文件只能是图片格式!');
          }
          if (!isLt1M) {
            this.$message.error('上传文件大小不能超过 1MB!');
          }
          return isIMAGE && isLt1M;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    属性

    参数说明dd类型可选值默认值
    action必选参数,上传的地址string
    headers设置上传的请求头部object
    multiple是否支持多选文件boolean
    data上传时附带的额外参数object
    name上传的文件字段名stringfile
    with-credentials支持发送 cookie 凭证信息booleanfalse
    show-file-list是否显示已上传文件列表booleantrue
    drag是否启用拖拽上传booleanfalse
    accept接受上传的文件类型(thumbnail-mode 模式下此参数无效)string
    on-preview点击文件列表中已上传的文件时的钩子function(file)
    on-remove文件列表移除文件时的钩子function(file, fileList)
    on-success文件上传成功时的钩子function(response, file, fileList)
    on-error文件上传失败时的钩子function(err, file, fileList)
    on-progress文件上传时的钩子function(event, file, fileList)
    on-change文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用function(file, fileList)
    before-upload上传文件之前的钩子,参数为上传的文件,若返回 false 或者返回 Promise 且被 reject,则停止上传。function(file)
    before-remove删除文件之前的钩子,参数为上传的文件和文件列表,若返回 false 或者返回 Promise 且被 reject,则停止删除。function(file, fileList)
    list-type文件列表的类型stringtext/picture/picture-cardtext
    auto-upload是否在选取文件后立即进行上传booleantrue
    file-list上传的文件列表, 例如: [{name: ‘food.jpg’, url: ‘https://xxx.cdn.com/xxx.jpg’}]array[]
    http-request覆盖默认的上传行为,可以自定义上传的实现function
    disabled是否禁用booleanfalse
    limit最大允许上传个数number
    on-exceed文件超出个数限制时的钩子function(files, fileList)-

    项目实例

    这里使用了,父组件向子组件传参,子组件向父组件传参

                
                  
                
    
    • 1
    • 2
    • 3

    父组件传参数

          // 上传附件
          fileActionUrl: CONFIG_URL.PUBLIC_CONFIG.baseURL + '/api/doc/UpLoadFile',
          fileAccept: '.doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf',
          filelimit: 1,
          filelistType: 'file',
          filetips: '只能上传办公文档,其它类型建议不要上传',
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    子组件接收参数,在props中定义

      // 接收父组件传递的值
      props: {
        // 动作action
        actionUrl: {
          type: String,
          required: true,
          default: '/api/doc/UpLoadFile'
        },
        // 接受上传的文件类型
        accept: {
          type: String,
          required: true
        },
        // 最大允许上传个数
        uploadlimit: {
          type: Number,
          required: true,
          default: 1
        },
    
        /** 文件列表的类型
         * drag是否启用拖拽上传
         * list-type 可选值 text/picture/picture-card
         **/
        listType: {
          type: String,
          required: true,
          default: 'text'
        },
        // 上传提示语
        tips: {
          type: String,
          required: false
        }
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    子组件向父组件回传数据

          // $emit() 向外触发父组件中方法,fileList由父组件传递过来
          this.$emit("fileList", this.ret_fileList)
    
    • 1
    • 2

    父组件接收子组件回传的数据,需要在watch监听器中实现,能够感知数据变化。

      watch: {
        // 监听文件列表变化
        fileList: {
          handler() {
            this.$emit('fileList', this.ret_fileList)
          }
        }
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    子组件代码

    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
  • 相关阅读:
    FreeRtos 任务切换深入分析
    【前端知识总结系列】第03篇
    Linux CC++ 网络编程博客
    高校档案室建设标准-高校数字档案室建设需考虑哪些因素
    10-热点文章-定时计算
    645. 错误的集合(javascript)645. Set Mismatch
    基于51单片机火灾监测自动灭火装置Proteus仿真
    openbabel包的安装
    软件测试 -- 自动化测试(Selenium)
    MCDF--lab03
  • 原文地址:https://blog.csdn.net/youcheng_ge/article/details/133947977