Browse Source

上传限制

秦鹏 3 years ago
parent
commit
d1419ade2d
1 changed files with 7 additions and 6 deletions
  1. 7 6
      src/components/Upload.vue

+ 7 - 6
src/components/Upload.vue

@@ -19,9 +19,7 @@
       :limit="filleNumber"
       :before-upload="handlebeforeUplaod"
     >
-      <el-button type="primary" v-if="type == '批量上传'">{{
-        $t("Key158")
-      }}</el-button>
+      <el-button type="primary" v-if="type == '批量上传'">{{ $t("Key158") }}</el-button>
       <el-button v-else>{{ $t("Key152") }}</el-button>
     </el-upload>
   </div>
@@ -66,6 +64,10 @@ export default {
   //方法集合
   methods: {
     handlebeforeUplaod(file) {
+      if (file.size > 20 * 1024 * 1024) {
+        this.$message.warning("上传文件大小不能超过20M");
+        return false; //必须返回false
+      }
       this.loading = this.$loading({
         lock: true,
         text: "Loading",
@@ -123,7 +125,7 @@ export default {
   activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
 };
 </script>
-<style lang='scss' scoped>
+<style lang="scss" scoped>
 //@import url(); 引入公共css类
 .uploadImage {
   width: 200px;
@@ -134,5 +136,4 @@ export default {
   align-items: center;
 }
 </style>
-<style lang="scss">
-</style>
+<style lang="scss"></style>