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

vue中el-upload上傳圖片到七牛的示例代碼

 更新時間:2018年10月19日 14:25:37   作者:baozisss  
這篇文章主要介紹了vue中el-upload上傳圖片到七牛的示例代碼,實(shí)現(xiàn)思路其實(shí)也很簡單,需要從后臺獲取七牛token上傳圖片到七牛,具體示例代碼大家跟隨小編一起學(xué)習(xí)吧

一、思路,從后臺獲取七牛token,上傳圖片到七牛,獲取返回圖片路徑放入el-upload。

二、代碼。

<el-input v-model="listVideoQuery.orgLogo" @change="orgLogoChange"></el-input>
  <el-col :span="10" class="mt10">
  <el-upload class="upload-demo" :file-list="fileList2" :action="domain" :before-upload="beforeAvatarUpload" :data="form"
  :on-remove="handleRemoveQrgLogo" :on-success="handleAvatarSuccess" list-type="picture" :limit="1" multiple>
  <el-button size="small" type="primary" @click="upPicName='orgLogo'">點(diǎn)擊上傳</el-button>
  <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
  </el-upload>
  </el-col>

export default {
 name: 'edit',
 data() {
 return {
 upPicName:'', //上傳圖片名字
 fileList1:[],
 form: {}, //上傳到七牛的token 
 bucketQuery:{
  bucket: 'website-image' //這是我用來獲取token傳給后臺的字段
 },
 domain: 'http://upload.qiniu.com', // 七牛云的上傳地址
 qiniuaddr: 'pd6rnk9ck.bkt.clouddn.com' // 這是七牛云空間的外鏈默認(rèn)域名
 }
 },
 methods: {
 // 上傳圖片規(guī)格
 beforeAvatarUpload (file) {
 const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
 const isLt2M = file.size / 1024 / 1024 < 5
 if (!isJPG) {
  return this.$message.error('上傳文件只能是 JPG或PNG 格式!')
 }
 if (!isLt2M) {
  return this.$message.error('上傳圖片大小不能超過 5MB!')
 }
 return upQiniu(this.bucketQuery).then(res => {
  this.form = {
  token:res.data
  }
 })
 },
 //圖片改變及上傳
 bannerPicChange(value) {
 this.fileList1 = []
 this.fileList1.push({
  name: value, 
  url: value
 }) 
 },
 handleBannerPicRemove(file, fileList) {
 this.fileList1 = []
 this.listVideoQuery.orgLogo= ''
 },
 handleAvatarSuccess(response) {
 if(this.upPicName =='orgLogo'){
  this.fileList1 = []
  this.fileList1.push({
  name: 'http://' + this.qiniuaddr + '/' + response.key, 
  url: 'http://' + this.qiniuaddr + '/' + response.key
  }) 
  this.listVideoQuery.orgLogo= 'http://' + this.qiniuaddr + '/' + response.key
 }
 this.$message({
  type: 'success',
  message: '上傳成功!',
  duration: 2000
 }) 
 },
 }
 }

三、效果。

總結(jié)

以上所述是小編給大家介紹的vue中el-upload上傳圖片到七牛的示例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

侯马市| 忻城县| 汕头市| 张北县| 滕州市| 沾益县| 吴堡县| 习水县| 电白县| 博罗县| 修武县| 东阿县| 金华市| 阜阳市| 塘沽区| 巧家县| 南平市| 宁陵县| 峨眉山市| 中江县| 利川市| 泰兴市| 额济纳旗| 天水市| 当雄县| 孟州市| 育儿| 治县。| 黎城县| 奉节县| 张家川| 麟游县| 彭泽县| 汾西县| 荥阳市| 岳普湖县| 德钦县| 天祝| 德化县| 延安市| 航空|