最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實現(xiàn)自定義視頻和圖片上傳的示例代碼

 更新時間:2023年04月21日 10:38:29   作者:Ann_R  
這篇文章主要為大家詳細介紹了如何通過Vue實現(xiàn)自定義視頻和圖片上傳的功能,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起學習一下

使用el-upload 上傳視頻總是報404錯誤,具體也不知道什么原因(如有知道的請評論告知,謝謝),去網上查了很多,代碼寫法確定是沒有問題的,最后改為axios上傳視頻,就沒出錯了,順便總結下圖片上傳

<template>
  <div class="body">
    <span>測試</span>
    <span>視頻上傳</span>
    <!-- style="display:none;" 隱藏input框 -->
    <input style="display:none;" class="input-video" multiple type="file" accept="video/*"
      @change="uploadVideo11($event)">
    <div v-if="!videoUrl" class="no-bg wh">
      <el-progress class="progress-video" v-if="progress" type="circle" :percentage="videoUploadPercent"></el-progress>
      <div v-if="!progress" @click="uploadVideo">
        <span>點擊上傳視頻</span>
      </div>
    </div>
    <video v-else="videoUrl" class="wh" v-bind:src="videoUrl" controls="controls">
      您的瀏覽器不支持視頻播放
    </video>

    <span>-------------------------------------------------------------------------</span>

    <span>圖片上傳</span>
    <!-- <el-upload 
      :disabled="disabled"  刪除圖片后禁止彈窗彈出
      :action="this.$store.state.updataurl"  圖片上傳路徑
      :headers="headers"  請求頭
      :show-file-list="false" 文件列表
      :on-success="handleAvatarSuccess" 上傳成功回調
      :before-upload="beforeAvatarUpload" 上傳前回調
      :on-remove="handleRemove" 移除回調
      :on-progress="picUploadProcess" 上傳進度條
      class="wh" > -->
    <el-upload :disabled="disabled" :action="this.$store.state.updataurl" :headers="headers" :show-file-list="false"
      :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" :on-remove="handleRemove"
      :on-progress="picUploadProcess" class="wh">
      <div v-if="cover" class="change-img wh">
        <!-- 地址拼接 -->
        <img :src="picUrl + cover" class="wh" />
        <div class="change">
          <span class="arr">更換</span>
          <span>&nbsp;|&nbsp;</span>
          <span class="arr" @click="handleRemove">刪除</span>
        </div>
      </div>
      <div v-else class="no-bg wh">
        <el-progress v-if="picFlag" type="circle" :percentage="picUploadPercent"></el-progress>
        <div v-else @click="disabled = false">
          <span class="note">點擊上傳封面圖片</span>
        </div>
      </div>
    </el-upload>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      // 視頻
      videoUrl: '', //視頻播放地址
      progress: false,
      videoUploadPercent: 0,

      // 圖片
      picUrl: this.$store.state.baseurl, //圖片前綴
      disabled: false,  //刪除圖片后禁止文件選擇彈窗彈出
      picFlag: false,   //進度條顯示標識
      picUploadPercent: 0,
      cover: ''
    }
  },
  computed: {
    headers() {
      return {
        Authorization: this.$store.getters.token || localStorage.getItem("token"),
        // soloFileName: 'video',   //和后端協(xié)商的默認標識
      };
    },
  },
  methods: {
    // 視頻上傳
    uploadVideo() {
      let ipFile = document.querySelector('.input-video')
      ipFile.click();
      this.videoUploadPercent = 0
    },
    async uploadVideo11(e) {
      // console.log("uploadVideo11", e)
      // console.log(e.target.files[0])
      this.progress = true
      let file = e.target.files[0]
      console.log("file", file)
      // multipart/form-data 格式
      let formData = new FormData()
      formData.append('file', file)
      let config = {
        //添加請求頭
        headers: {
          Authorization: this.$store.getters.token || localStorage.getItem("token"),
          "Content-Type": "multipart/form-data"
        },
        // 添加進度條
        onUploadProgress: (progressEvent) => {
          this.videoUploadPercent = Number((progressEvent.loaded / progressEvent.total * 100).toFixed(0)) * 1
          // console.log("this.videoUploadPercent", this.videoUploadPercent)
        }
      };
      axios.post(this.$store.state.videoUploadUrl, formData, config, { timeout: 1000 * 60 * 2 })	 //設置超時2分鐘
        .then(async (res) => {
          console.log("視頻上傳", res);
          this.videoUrl = res.data.data.playUrl  //端傳過來的視頻播放地址
          if (this.videoUrl) {
            this.progress = false
            this.$message({
              message: '上傳成功',
              type: 'success'
            });
          }
        }).catch(err => {
          this.progress = false
          console.log(err);
          this.$message.error({
            message: '上傳失敗'
          });
        })
    },

    // 圖片上傳
    handleAvatarSuccess: function (response, file, fileList) {
      if (file.response.code == 200) {
        this.cover = file.response.data.src;  //后端傳過來的圖片地址
        this.picFlag = false
        this.picUploadPercent = 0
      }
    },
    handleRemove(file) {
      this.cover = ''
      this.disabled = true
      // 1.獲取將要刪除圖片的臨時路徑
      // const filePath = file.response.data.tmp_path
      // // 2.從pics數(shù)組中,找到圖片對應的索引值
      // const i = this.formData.pics.findIndex(x => x.pic === filePath)
      // // 3.調用splice方法,移除圖片信息
      // this.formData.splice(i, 1)
    },
    beforeAvatarUpload(file) {
      const isIMG = /^image\/(jpe?g|png|gif)$/.test(file.type);
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isIMG) {
        this.$message.error("上傳圖片只能是 JPG/PNG/GIF 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上傳圖片大小不能超過 2MB!");
      }
      return isIMG && isLt2M;
    },
    picUploadProcess(event, file, fileList) {
      this.picFlag = true;
      this.picUploadPercent = file.percentage.toFixed(0) * 1;
    },
  }
}
</script>

<style lang="less" scoped>
// 進度條
/deep/ .el-progress-circle {
  height: 100px !important;
  width: 100px !important;
}

.body {
  display: flex;
  flex-direction: column;
}

.no-bg {
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px dashed #000000;
  background-color: #FBFBFC;
  border-radius: 5px;
  cursor: pointer; //變小手
}

.wh {
  width: 320px;
  height: 180px;
  border-radius: 5px;
}

.change-img {
  position: relative;

  .change {
    opacity: 0;
    position: absolute;
    bottom: 8%;
    left: 35%;
    padding: 6px 11px;
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    color: #FFFFFF;
  }
}

.change-img:hover .change {
  opacity: 1;
}

.arr {
  cursor: default;
}
</style>

到此這篇關于Vue實現(xiàn)自定義視頻和圖片上傳的示例代碼的文章就介紹到這了,更多相關Vue視頻 圖片上傳內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Vscode如何創(chuàng)建vue項目

    Vscode如何創(chuàng)建vue項目

    這篇文章主要介紹了Vscode如何創(chuàng)建vue項目問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • Vue中對組件二開解決思路以及方案

    Vue中對組件二開解決思路以及方案

    這篇文章主要介紹了Vue中對組件二開解決思路以及方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2023-04-04
  • 優(yōu)化Vue中date format的性能詳解

    優(yōu)化Vue中date format的性能詳解

    這篇文章主要介紹了優(yōu)化Vue中date format的性能詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-01-01
  • vue單行文本溢出會出現(xiàn)title提示自定義指令

    vue單行文本溢出會出現(xiàn)title提示自定義指令

    這篇文章主要為大家介紹了vue單行文本溢出會出現(xiàn)title提示自定義指令,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • unplugin-auto-import與unplugin-vue-components安裝問題解析

    unplugin-auto-import與unplugin-vue-components安裝問題解析

    這篇文章主要為大家介紹了unplugin-auto-import與unplugin-vue-components問題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • Vue3.0手寫輪播圖效果

    Vue3.0手寫輪播圖效果

    這篇文章主要為大家詳細介紹了Vue3.0手寫輪播圖效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 關于Uncaught(in?promise)TypeError:?list?is?not?iterable報錯解決

    關于Uncaught(in?promise)TypeError:?list?is?not?iterable報錯

    這篇文章主要給大家介紹了關于Uncaught(in?promise)TypeError:?list?is?not?iterable報錯的解決方法,文中通過示例代碼介紹的非常詳細,對大家學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-08-08
  • vue element el-form 多級嵌套驗證的實現(xiàn)示例

    vue element el-form 多級嵌套驗證的實現(xiàn)示例

    本文主要介紹了vue element el-form 多級嵌套驗證的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08
  • 使用ElementUI中el-upload上傳文件轉base64格式

    使用ElementUI中el-upload上傳文件轉base64格式

    這篇文章主要介紹了使用ElementUI中el-upload上傳文件轉base64格式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • Vue中全局變量的定義和使用

    Vue中全局變量的定義和使用

    這篇文章主要介紹了vue中全局變量的定義和使用,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06

最新評論

武陟县| 昭通市| 巴林右旗| 清水县| 洛阳市| 东乌| 江孜县| 台中县| 虹口区| 阿拉善右旗| 寻乌县| 静海县| 东兴市| 南宁市| 新丰县| 哈尔滨市| 藁城市| 广汉市| 新津县| 镇赉县| 德江县| 辉南县| 兰坪| 科技| 恩施市| 永定县| 得荣县| 余姚市| 微博| 济宁市| 建水县| 封丘县| 库伦旗| 平潭县| 都匀市| 永靖县| 秭归县| 潞西市| 汉阴县| 蒙城县| 夏邑县|