专栏目标
在vue和element UI联合技术栈的操控下,本专栏提供行之有效的源代码示例和信息点介绍,做到灵活运用。
(1)提供vue2的一些基本操作:安装、引用,模板使用,computed,watch,生命周期(beforeCreate,created,beforeMount,mounted, beforeUpdate,updated, beforeDestroy,destroyed,activated,deactivated,errorCaptured,components,)、 $root , $parent , $children , $slots , $refs , props, $emit , eventbus ,provide / inject, Vue.observable, $listeners, $attrs, $nextTick , v-for, v-if, v-else,v-else-if,v-on,v-pre,v-cloak,v-once,v-model, v-html, v-text, keep-alive,slot-scope, filters, v-bind,.stop, .native, directives,mixin,render,国际化,Vue Router等
(2)提供element UI的经典操作:安装,引用,国际化,el-row,el-col,el-button,el-link,el-radio,el-checkbox ,el-input,el-select, el-cascader, el-input-number, el-switch,el-slider, el-time-picker, el-date-picker, el-upload, el-rate, el-color-picker, el-transfer, el-form, el-table, el-tree, el-pagination,el-badge,el-avatar,el-skeleton, el-empty, el-descriptions, el-result, el-statistic, el-alert, v-loading, $message, $alert, $prompt, $confirm , $notify, el-breadcrumb, el-page-header,el-tabs ,el-dropdown,el-steps,el-dialog, el-tooltip, el-popover, el-popconfirm, el-card, el-carousel, el-collapse, el-timeline, el-divider, el-calendar, el-image, el-backtop,v-infinite-scroll, el-drawer等
本文章目录
- 效果图
- template中片段
- data()和computed:{}中数据
- methods:{} 中核心方法数据
在使用el-upload的时候,上传文件到服务器,有时候后台要求上传token,怎么处理呢?以下是一个示例。
效果图
template中片段
<el-dialog
:modal-append-to-body="false"
title="上传文件"
:visible.sync="isUpload"
width="390px"
:close-on-click-modal="false"
ref="upload"
>
<el-upload
class="upload-demo"
accept=".jar"
drag
:action="uploadUrl"
:file-list="fileList"
:headers="headerToken"
:on-success="onSuccess"
:before-upload="beforeUpload"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传jar文件,且不超过30Mb</div>
</el-upload>
<span slot="footer">
<el-button type="warning" @click="cancelUpload()">取消上传</el-button>
</span>
</el-dialog>
data()和computed:{}中数据
data(){
return {
isUpload:false,
uploadUrl:this.$api.firmwareUpload,
}
},
computed: {
headerToken(){
return { "authorize":localStorage.getItem('token') } }
},
methods:{} 中核心方法数据
/* ** 名称:上传文件*/
beforeUpload(file) {
var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
const fileType1 = testmsg === 'jar'
const isLt30M = file.size / 1024 / 1024 < 30
if(!fileType1) {
this.$message({
message: '上传文件只能是 jar格式!',
type: 'warning'
});
}
if(!isLt30M) {
this.$message({
message: '上传文件大小不能超过 30MB!',
type: 'warning'
});
}
return fileType1 && isLt30M
} ,
onSuccess(file, fileList){
this.$message({
type: 'success',
message: '上传成功!'
});
this.isUpload=false;
},