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

Element UI upload 圖片上傳功能

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

ruoyi實(shí)現(xiàn)不需要token訪問靜態(tài)資源

在config/SecurityConfig配置

.antMatchers(
                        HttpMethod.GET,
                        "/",
                        "/*.html",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js",
                        //profile下有很多文件,只開放頭像類的文件
                        "/profile/upload/**",
                        "/profile/**",
                        "/profile/avatar/**"

"/xxx/**"讓xxx路徑下的全部文件訪問不需要token

在config/ResourcesConfig中增加

        /** 本地文件上傳路徑 */
        registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
                .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");

前端加入Element Ui upload組件組件

<template>
  <div ref="dasd">
    <el-upload
      class="img-upload"
      ref="upload"
      action="http://localhost:8080/dss/ServiceStd/uploadimg"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :headers="header"
      :before-remove="beforeRemove"
      :on-success="handleSuccess"
      multiple
      :limit="1"
      :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>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth';
export default {
  name: 'ImgUpload',
  data () {
    return {
      fileList: [],
      url: '',
      header: {
        Authorization: 'Bearer ' + getToken()
      }
    }
  },

  methods: {
    handleRemove (file, fileList) {
      this.$emit("clearImageUrl")
    },
    handlePreview (file) {
    },
    handleExceed (files, fileList) {
      this.$message.warning(`當(dāng)前限制選擇 1 個(gè)文件,本次選擇了 ${files.length} 個(gè)文件,共選擇了 ${files.length + fileList.length} 個(gè)文件`)
    },
    beforeRemove (file, fileList) {
      return this.$confirm(`確定移除 ${file.name}`)
    },
    handleSuccess (response) {
      this.url = response
      this.$emit('onUpload')
      this.$message.warning('上傳成功')
    },
    clear () {
      this.$refs.upload.clearFiles()
    },

  }
}
</script>

解決Element ui上傳圖片時(shí)未攜帶token訪問不到服務(wù)器問題

在data()里面加入header屬性設(shè)置子屬性Authorization

data () {
    return {
		header: {
        Authorization: 'Bearer ' + getToken()
      }
    }

在el-upload里設(shè)置

<el-upload
:headers="header"
>

解決upload組件重新進(jìn)入上傳時(shí)清除上次上傳

在提交時(shí)

            <el-form-item label="作業(yè)標(biāo)準(zhǔn)示范" prop="OpeStdThr">
              <el-input v-model="form.OpeStd" autocomplete="off" placeholder="圖片 URL" readonly></el-input>
             <img-upload @onUpload="uploadImg" ref="imgUpload" @clearImageUrl="clearImageUrl(1)"></img-upload>
            </el-form-item>

在提交時(shí)新增clear()方法調(diào)用子組件里clear方法

submitForm: function () {
          this.$refs.imgUpload.clear();
        }

刪除圖片時(shí)同時(shí)刪除URl

element上傳圖片到服務(wù)器,javascript,前端,elementui
加入@clearImageUrl綁定方法

            <el-form-item label="作業(yè)標(biāo)準(zhǔn)示范" prop="OpeStdThr">
              <el-input v-model="form.OpeStd" autocomplete="off" placeholder="圖片 URL" readonly></el-input>
             <img-upload @onUpload="uploadImg" ref="imgUpload" @clearImageUrl="clearImageUrl(1)"></img-upload>
            </el-form-item>

clearImageUrl(1) 括號(hào)內(nèi)可以直接攜帶參數(shù),根據(jù)參數(shù)執(zhí)行哪種方法文章來源地址http://www.zghlxwxcb.cn/news/detail-627186.html

    clearImageUrl(type) {
      if (type == 1) {
      	//delImgUrl調(diào)用后端接口刪除已上傳的照片
        delImgUrl(this.form.OpeStdOne);
        this.form.OpeStdOne = '';
      }else if (type ==2) {
        delImgUrl(this.form.OpeStdTwo);
        this.form.OpeStdTwo = '';
      }else if (type == 3) {
        delImgUrl(this.form.OpeStdThr);
        this.form.OpeStdThr = '';
      }
    }

delImgUrl可以采用兩種方式

  1. 使用緩存,到了一定圖片數(shù)量再去刪除
  2. 直接去后臺(tái)刪除

到了這里,關(guān)于Element UI 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)文章

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包