1,分页数据处理
<el-pagination
background
layout="prev, pager, next"
@current-change="handleCurrentChange"
:page-size="9"
:current-page.sync="pageNo"
:total="parseInt(total)" //total的值要到后台获取
></el-pagination>
handleCurrentChange() {
this.load();//这是要加载的函数
}
//计算方法
computed: {
pageNo: {
get() {
return Number(this.$route.query.pageNo || 1); //获取url上面pageNo的值
},
set(pageNo) {
this.$router.push({
query: { ...this.$route.query, pageNo }
});
}
}
},
2,文件上传组件upload —— 如何将文件传到后端
<el-form-item label="" prop="expvmFiles">
<el-upload
class="upload-demo"
drag
ref="uploadfile"
:action="upload_url"
:auto-upload="false"
:before-upload="newFiles"
multiple>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div slot="tip" class="el-upload__tip">实验信息附件上传,只能传(.file)文件</div>
</el-upload>
</el-form-item>
<el-form-item label="" prop="expvmVideo">
<el-upload
class="upload-demo"
drag
ref="uploadvideo"
:action="upload_url"
:auto-upload="false"
:before-upload="newVideo"
accept=".mp4">
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div slot="tip" class="el-upload__tip">实验视频上传,只能传(.mp4)文件</div>
</el-upload>
</el-form-item>
data () {
return {
upload_url: 'aaa', // 随便填一个,但一定要有
uploadForm: new FormData(), // 一个formdata
rules: {}, // 用到的规则
}
}
methods:
newSubmitForm () {
this.$refs['newform'].validate((valid) => {
if (valid) {
this.uploadForm.append('expName', this.newform.expName)
this.uploadForm.append('expSn', this.newform.expSn)
this.uploadForm.append('groupId', this.newgroupId)
this.uploadForm.append('subGroupId', this.newsubgroupId)
this.uploadForm.append('expvmDifficulty', this.newform.expvmDifficulty)
newExp(this.uploadForm).then(res => {
if (res.code === 400) {
this.$message.error(res.error)
} else if (res.code === 200) {
this.$message.success('上传成功!')
}
})
this.$refs.uploadhtml.submit() // 提交时触发了before-upload函数
this.$refs.uploadfile.submit()
this.$refs.uploadvideo.submit()
} else {
console.log('error submit!!')
return false
}
})
},
newFiles (file) {
this.uploadForm.append('file[]', file)
return false
}
newVideo (file) {
this.uploadForm.append('video[]', file)
return false
}
select 筛选传值
<el-select v-model="value" placeholder="状态" @change="selection">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
methods:
selection() {
console.log(this.value);
this.unitsLoad();//需要加载的函数
},
const unit = await findListUnits(this.id, this.value); //把值传给请求到的接口