vue图片上传后显示

 直接看样子吧,点那个相机可以上传照片,然后在下面显示,可以根据自己的要求更换图片的位置、删除(当然,没做拖拽)

单纯改变数组位置,界面是不能刷新的,因为js不检测数组变化,但是会检测数组长度变化

html

      <div class="container">
        <div class="c-card-ico">
          <div style="width: 20vw;display: inline-block;text-align: right">商品描述图:</div>
          <div class="fl mlr10">
            <img src="../../assets/image/uploading.jpg" @click="clp1()"/>
            <input type="file" id="photoList" @input="con1" ref="photoList"/>
          </div>
        </div>

        <div class="flfw mt20" style="margin-left: 200px;">
          <div class="m10" v-for="(list,index) in photoList">
            <div style="position: relative" class="main">
              <img style="width: 150px;height: 100px;" :src="list" />
              <div class="flex-around ico" style="position: absolute">
                <img src="../../assets/image/left.png" @click="left(index)" alt="">
                <img src="../../assets/image/del.png" @click="del(index)" alt="">
                <img src="../../assets/image/right.png" @click="right(index)" alt="">
              </div>
            </div>
          </div>
        </div>

      </div>

css(搞个demo而已,样式有点随便,可以自己随便写)

<style lang="less">
.flfw{
  display: flex;
  flex-wrap: wrap;
}
.mt20{
  margin-top: 20px;
}
.m10{
  margin: 10px;
}

  .container{
    width: 100%;
    .c-card-ico{
      display: flex;
      align-items: center;
      width: 100%;
      margin-top: 10px;
      span{
        display: inline-block;
        text-align: right;
      }
      img{
        width: 150px;
        height: 100px;
      }
      /*img:hover .ico{*/
      /*  display: block;*/
      /*}*/
      input{
        /*visibility: hidden;*/
        display: none;
      }
    }

    .ico{
      width: 150px;
      height: 100px;
      margin-top: -100px;
      background-color: rgba(0,0,0,0.7);
      display: none;
      img{
        width: 30px;
      }
    }
    .main:hover .ico{
      display: flex;
    }
</style>

js

data(){
    return{
        photoList:[]//图片数组
    }
},
methods:{
    uploadFile (img) {
        return new Promise((resolve, reject) => {
          let formData = new FormData()
          formData.append('images', img)
          //this.global.base.uploadFile为我的图片上传地址,而images是后端要求的文件名
          postAjax(this.global.base.uploadFile, formData).then(res => {
            resolve(res.data)
          }).catch(err => {
            reject(err)
          })
        })
      },
      //图片
      clp1(){
        return this.$refs.photoList.click();
      },
      con1(e){
        this.uploadFile(e.target.files[0]).then(res=>{
          this.photoList.push(res.image0)
        })
      },
      left(index){
        if(index === 0){
          return
        }
        let a,photoList = this.photoList
        a = photoList[index]
        photoList[index] = photoList[index-1]
        photoList[index-1] = a
        this.photoList = []
        this.photoList = photoList
      },
      del(index){
        this.photoList.splice(index,1)
      },
      right(index){
        if(index+1 === this.photoList.length){
          return
        }
        let a,photoList = this.photoList
        a = photoList[index]
        photoList[index] = photoList[index+1]
        photoList[index+1] = a
        this.photoList = []
        this.photoList = photoList
      }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本门课程重实战,将基础知识拆解到项目里,让你在项目情境里学知识。 这样的学习方式能让你保持兴趣、充满动力,时刻知道学的东西能用在哪、能怎么用。 平时不明白的知识点,放在项目里去理解就恍然大悟了。   一、融汇贯通 本视频采用了前后端分离的开发模式,前端使用Vue.js+Element UI实现了Web页面的呈现,后端使用Python 的Django框架实现了数据访问的接口,前端通过Axios访问后端接口获得数据。在学习完本章节后,真正理解前后端的各自承担的工作。   二、贴近实战 本系列课程为练手项目实战:学生管理系统v4.0的开发,项目包含了如下几个内容:项目的总体介绍、基本功能的演示、Vuejs的初始化、Element UI的使用、在Django中实现针对数据的增删改查的接口、在Vuejs中实现前端增删改查的调用、实现文件的上传、实现表格的分页、实现导出数据到Excel、实现通过Excel导入数据、实现针对表格的批量化操作等等,所有的功能都通过演示完成、贴近了实战   三、课程亮点 在本案例中,最大的亮点在于前后端做了分离,真正理解前后端的各自承担的工作。前端如何和后端交互   适合人群: 1、有Python语言基础、web前端基础,想要深入学习Python Web框架的朋友; 2、有Django基础,但是想学习企业级项目实战的朋友; 3、有MySQL数据库基础的朋友  

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值