国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ElementUI淺嘗輒止38:Upload 上傳

這篇具有很好參考價(jià)值的文章主要介紹了ElementUI淺嘗輒止38:Upload 上傳。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

通過點(diǎn)擊或者拖拽上傳文件實(shí)現(xiàn)上傳功能,常見于文件、文件夾或圖片上傳,使用挺頻繁的。需要熟練掌握

1.如何使用?點(diǎn)擊上傳

通過 slot 你可以傳入自定義的上傳按鈕類型和文字提示??赏ㄟ^設(shè)置limiton-exceed來限制上傳文件的個(gè)數(shù)和定義超出限制時(shí)的行為??赏ㄟ^設(shè)置before-remove來阻止文件移除操作。

<el-upload
  class="upload-demo"
  action="https://jsonplaceholder.typicode.com/posts/"
  :on-preview="handlePreview"
  :on-remove="handleRemove"
  :before-remove="beforeRemove"
  multiple
  :limit="3"
  :on-exceed="handleExceed"
  :file-list="fileList">
  <el-button size="small" type="primary">點(diǎn)擊上傳</el-button>
  <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
</el-upload>
<script>
  export default {
    data() {
      return {
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    methods: {
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      handleExceed(files, fileList) {
        this.$message.warning(`當(dāng)前限制選擇 3 個(gè)文件,本次選擇了 ${files.length} 個(gè)文件,共選擇了 ${files.length + fileList.length} 個(gè)文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`確定移除 ${ file.name }?`);
      }
    }
  }
</script>

2.用戶頭像上傳

使用?before-upload?限制用戶上傳的圖片格式和大小。

<el-upload
  class="avatar-uploader"
  action="https://jsonplaceholder.typicode.com/posts/"
  :show-file-list="false"
  :on-success="handleAvatarSuccess"
  :before-upload="beforeAvatarUpload">
  <img v-if="imageUrl" :src="imageUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
  export default {
    data() {
      return {
        imageUrl: ''
      };
    },
    methods: {
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上傳頭像圖片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上傳頭像圖片大小不能超過 2MB!');
        }
        return isJPG && isLt2M;
      }
    }
  }
</script>

3.照片墻

使用?list-type?屬性來設(shè)置文件列表的樣式。

<el-upload
  action="https://jsonplaceholder.typicode.com/posts/"
  list-type="picture-card"
  :on-preview="handlePictureCardPreview"
  :on-remove="handleRemove">
  <i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
  <img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<script>
  export default {
    data() {
      return {
        dialogImageUrl: '',
        dialogVisible: false
      };
    },
    methods: {
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      }
    }
  }
</script>

4.文件縮略圖

使用?scoped-slot?去設(shè)置縮略圖模版。

<el-upload
  action="#"
  list-type="picture-card"
  :auto-upload="false">
    <i slot="default" class="el-icon-plus"></i>
    <div slot="file" slot-scope="{file}">
      <img
        class="el-upload-list__item-thumbnail"
        :src="file.url" alt=""
      >
      <span class="el-upload-list__item-actions">
        <span
          class="el-upload-list__item-preview"
          @click="handlePictureCardPreview(file)"
        >
          <i class="el-icon-zoom-in"></i>
        </span>
        <span
          v-if="!disabled"
          class="el-upload-list__item-delete"
          @click="handleDownload(file)"
        >
          <i class="el-icon-download"></i>
        </span>
        <span
          v-if="!disabled"
          class="el-upload-list__item-delete"
          @click="handleRemove(file)"
        >
          <i class="el-icon-delete"></i>
        </span>
      </span>
    </div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
  <img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<script>
  export default {
    data() {
      return {
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false
      };
    },
    methods: {
      handleRemove(file) {
        console.log(file);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleDownload(file) {
        console.log(file);
      }
    }
  }
</script>

5.圖片列表縮略圖

<el-upload
  class="upload-demo"
  action="https://jsonplaceholder.typicode.com/posts/"
  :on-preview="handlePreview"
  :on-remove="handleRemove"
  :file-list="fileList"
  list-type="picture">
  <el-button size="small" type="primary">點(diǎn)擊上傳</el-button>
  <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
</el-upload>
<script>
  export default {
    data() {
      return {
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    methods: {
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      }
    }
  }
</script>

6.上傳文件列表控制

通過?on-change?鉤子函數(shù)來對(duì)列表進(jìn)行控制

<el-upload
  class="upload-demo"
  action="https://jsonplaceholder.typicode.com/posts/"
  :on-change="handleChange"
  :file-list="fileList">
  <el-button size="small" type="primary">點(diǎn)擊上傳</el-button>
  <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
</el-upload>
<script>
  export default {
    data() {
      return {
        fileList: [{
          name: 'food.jpeg',
          url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
        }, {
          name: 'food2.jpeg',
          url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
        }]
      };
    },
    methods: {
      handleChange(file, fileList) {
        this.fileList = fileList.slice(-3);
      }
    }
  }
</script>

7.拖拽上傳

<el-upload
  class="upload-demo"
  drag
  action="https://jsonplaceholder.typicode.com/posts/"
  multiple>
  <i class="el-icon-upload"></i>
  <div class="el-upload__text">將文件拖到此處,或<em>點(diǎn)擊上傳</em></div>
  <div class="el-upload__tip" slot="tip">只能上傳jpg/png文件,且不超過500kb</div>
</el-upload>

8.手動(dòng)上傳

<el-upload
  class="upload-demo"
  ref="upload"
  action="https://jsonplaceholder.typicode.com/posts/"
  :on-preview="handlePreview"
  :on-remove="handleRemove"
  :file-list="fileList"
  :auto-upload="false">
  <el-button slot="trigger" size="small" type="primary">選取文件</el-button>
  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上傳到服務(wù)器</el-button>
  <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
</el-upload>
<script>
  export default {
    data() {
      return {
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    methods: {
      submitUpload() {
        this.$refs.upload.submit();
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      }
    }
  }
</script>

關(guān)于上傳組件的大致內(nèi)容就是這些,需要繼續(xù)深入淺出的,可前往上傳組件文章來源地址http://www.zghlxwxcb.cn/news/detail-702240.html

到了這里,關(guān)于ElementUI淺嘗輒止38:Upload 上傳的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • ElementUI淺嘗輒止18:Avatar 頭像

    用圖標(biāo)、圖片或者字符的形式展示用戶或事物信息。 常用于管理系統(tǒng)或web網(wǎng)站的用戶頭像,在用戶賬戶模塊更換頭像操作也能看到關(guān)于Avatar組件的應(yīng)用。 通過? shape ?和? size ?設(shè)置頭像的形狀和大小。 支持三種類型:圖標(biāo)、圖片和字符 當(dāng)展示類型為圖片的時(shí)候,圖片加載失

    2024年02月09日
    瀏覽(18)
  • ElementUI淺嘗輒止16:Tag 標(biāo)簽

    用于標(biāo)記和選擇。 動(dòng)態(tài)編輯標(biāo)簽可以通過點(diǎn)擊標(biāo)簽關(guān)閉按鈕后觸發(fā)的? close ?事件來實(shí)現(xiàn) Tag 組件提供除了默認(rèn)值以外的三種尺寸,可以在不同場(chǎng)景下選擇合適的按鈕尺寸。 Tag 組件提供了三個(gè)不同的主題: dark 、 light ?和? plain ?

    2024年02月10日
    瀏覽(22)
  • ElementUI淺嘗輒止26:Notification 通知

    懸浮出現(xiàn)在頁面角落,顯示全局的通知提醒消息。 適用性廣泛的通知欄 帶有 icon,常用來顯示「成功、警告、消息、錯(cuò)誤」類的系統(tǒng)消息 可以讓 Notification 從屏幕四角中的任意一角彈出 使用 position 屬性定義 Notification 的彈出位置,支持四個(gè)選項(xiàng): top-right 、 top-left 、 bottom

    2024年02月09日
    瀏覽(15)
  • ElementUI淺嘗輒止33:Form 表單

    包括各種表單項(xiàng),比如輸入框、選擇器、開關(guān)、單選框、多選框等。 W3C 標(biāo)準(zhǔn)中有如下規(guī)定: When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form. 即:當(dāng)一個(gè) form 元素中只有一個(gè)輸入框時(shí),在該輸入框中按下回車應(yīng)提交

    2024年02月09日
    瀏覽(29)
  • ElementUI淺嘗輒止15:Table 表格

    用于展示多條結(jié)構(gòu)類似的數(shù)據(jù),可對(duì)數(shù)據(jù)進(jìn)行排序、篩選、對(duì)比或其他自定義操作。 Table組件比較常用,常見于數(shù)據(jù)查詢,報(bào)表頁面,用來展示表格數(shù)據(jù)。 使用帶斑馬紋的表格,可以更容易區(qū)分出不同行的數(shù)據(jù)。 可將表格內(nèi)容 highlight 顯示,方便區(qū)分「成功、信息、警告、危

    2024年02月09日
    瀏覽(21)
  • ElementUI淺嘗輒止28:Dropdown 下拉菜單

    將動(dòng)作或菜單折疊到下拉菜單中。 移動(dòng)到下拉菜單上,展開更多操作。 可使用按鈕觸發(fā)下拉菜單。 可以配置 click 激活或者 hover 激活。 可以 hide-on-click 屬性來配置。 點(diǎn)擊菜單項(xiàng)后會(huì)觸發(fā)事件,用戶可以通過相應(yīng)的菜單項(xiàng) key 進(jìn)行不同的操作 Dropdown 組件提供除了默認(rèn)值以外的

    2024年02月09日
    瀏覽(90)
  • ElementUI淺嘗輒止32:NavMenu 導(dǎo)航菜單

    為網(wǎng)站提供導(dǎo)航功能的菜單。常用于網(wǎng)站平臺(tái)頂部或側(cè)邊欄菜單導(dǎo)航。 垂直菜單,可內(nèi)嵌子菜單。

    2024年02月09日
    瀏覽(16)
  • ElementUI淺嘗輒止36:Input 輸入框

    通過鼠標(biāo)或鍵盤輸入字符 Input 為受控組件,它 總會(huì)顯示 Vue 綁定值 。 通常情況下,應(yīng)當(dāng)處理? input ?事件,并更新組件的綁定值(或使用 v-model )。否則,輸入框內(nèi)顯示的值將不會(huì)改變。不支持? v-model ?修飾符。 通過? disabled ?屬性指定是否禁用 input 組件 使用 clearable 屬性

    2024年02月09日
    瀏覽(20)
  • ElementUI淺嘗輒止27:Steps 步驟條

    引導(dǎo)用戶按照流程完成任務(wù)的分步導(dǎo)航條,可根據(jù)實(shí)際應(yīng)用場(chǎng)景設(shè)定步驟,步驟不得少于 2 步。 設(shè)置 active 屬性,接受一個(gè) Number ,表明步驟的 index,從 0 開始。需要定寬的步驟條時(shí),設(shè)置 space 屬性即可,它接受 Number ,單位為 px ,如果不設(shè)置,則為自適應(yīng)。設(shè)置 finish-stat

    2024年02月09日
    瀏覽(21)
  • ElementUI淺嘗輒止14:Carousel 走馬燈

    在有限空間內(nèi),循環(huán)播放同一類型的圖片、文字等內(nèi)容 結(jié)合使用 el-carousel 和 el-carousel-item 標(biāo)簽就得到了一個(gè)走馬燈?;脽羝膬?nèi)容是任意的,需要放在 el-carousel-item 標(biāo)簽中。默認(rèn)情況下,在鼠標(biāo) hover 時(shí)底部的指示器時(shí)就會(huì)觸發(fā)切換。通過設(shè)置 trigger 屬性為 click ,可以達(dá)到點(diǎn)

    2024年02月10日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包