国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue圖片上傳本地預覽組件使用詳解

2019-11-19 12:05:54
字體:
來源:轉載
供稿:網友

最近項目一直在使用vue,以前只是用vue做過一些簡單的demo對數據進行增刪改,并沒有用于實際開發項目。今天就想了解一下如何用vue實現常見的圖片上傳前本地預覽效果。

效果預覽:

<template> <div class="image-view">  <div class="addbox">   <input type="file" @change="getImgBase()">   <div class="addbtn">+</div>  </div>  <div class="view">   <div class="item" v-for="(item, index) in imgBase64">    <span class="cancel-btn" @click="delImg(index)">x</span>    <img :src="item">   </div>  </div> </div></template><script> export default {  name: 'imageView',  data (){   return {    imgBase64:[] //存儲img base64的值將值傳給后端處理   }  },  methods: {   //獲取圖片base64實現預覽   getImgBase(){    var _this = this;    var event = event || window.event;    var file = event.target.files[0];    var reader = new FileReader();     //轉base64    reader.onload = function(e) {     _this.imgBase64.push(e.target.result);    }    reader.readAsDataURL(file);   },   //刪除圖片   delImg(index){    this.imgBase64.splice(index,1);   }  } }</script><style scoped> *{margin:0 auto;padding:0;font-family:"微軟雅黑";} .clearboth::after{  content:"";  display:block;  clear:both; } .image-view{  width:400px;  height:300px;  margin:50px auto; } .image-view .addbox{  float:left;  position:relative;  height:100px;  width:100px;  margin-bottom:20px;  text-align:center; } .image-view .addbox input{  position:absolute;  left:0;  height:100px;  width:100px;  opacity:0; } .image-view .addbox .addbtn{  float:left;  height:100px;  width:100px;  line-height:100px;  color:#fff;  font-size:40px;  background:#ccc;  border-radius:10px; } .image-view .item {  position:relative;  float:left;  height:100px;  width:100px;  margin:10px 10px 0 0; } .image-view .item .cancel-btn{  position:absolute;  right:0;  top:0;  display:block;  width:20px;  height:20px;  color:#fff;  line-height:20px;  text-align:center;  background:red;  border-radius:10px;  cursor:pointer; } .image-view .item img{  width:100%;  height:100%; } .image-view .view{  clear:both; }</style>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万州区| 宁海县| 手机| 吉木乃县| 怀来县| 江西省| 铜梁县| 华亭县| 余庆县| 乐至县| 郓城县| 隆化县| 资溪县| 襄垣县| 团风县| 沧州市| 衡阳县| 金乡县| 佳木斯市| 麻栗坡县| 南和县| 红原县| 周至县| 垣曲县| 景德镇市| 舒城县| 平泉县| 安塞县| 浏阳市| 邵东县| 金平| 黄龙县| 平阴县| 安顺市| 新平| 广宁县| 尼玛县| 大理市| 屯门区| 岢岚县| 临潭县|