亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例

 更新時間:2020年07月31日 10:04:35   作者:達(dá)大大  
這篇文章主要介紹了vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

項目需求,嵌到elementUi里的小組件,寫得不好,不喜勿噴,謝謝

父組件代碼

<template>
 <div>
 <see-attachment :filesLists='files' :file='imgFile' v-if="showmask" @hideMask='showmask=false'></see-attachment>
 </div>
</template>
<script>
 import seeAttachment from "./seeAttachment.vue";
 export default {
 data() {
 return {
 showmask: false,
 imgFile: {}
 };
 },
 components: {
 seeAttachment
 },
 methods: {
 lookImg(f) {
 this.showmask = true;
 this.imgFile = f;
 },
 }
 };
</script>

子組件代碼

<template>
 <div>
 <div class="proview_box" @click="hideMask">
 <div class="img_box">
 <img :src="imgPath" :width="width" :height="height" @click="stopEvent" id='img' />
 </div>
 </div>
 <div class="handleImg_box">
 <div @click="prevOne"><img src="../../../../static/img/prev.png" /></div>
 <div @click="rotate(0)"><img src="../../../../static/img/turn_left.png" /></div>
 <div @click="rotate(1)"><img src="../../../../static/img/turn_right.png" /></div>
 <div @click="nextOne"><img src="../../../../static/img/next.png" /></div>
 </div>
 </div>
</template>
<script>
 export default {
 name: 'seeAttachment',
 props: ['filesLists', 'file'],
 data: function() {
 return {
 imgPath: '',
 width: 0,
 height: 0,
 imgIndex: 0
 }
 },
 mounted() {
 this.getImgIndex();
 this.seeAttachment(this.imgIndex);
 },
 computed: {
 //去掉不是圖片的附件
 imgList() {
 const ARR = ["png", "PNG", "jpeg", "JPEG", "bmp", "BMP", "jpg", "JPG", "gif", "GIF"];
 let arrs = '';
 let suffix = '';
 let type = '';
 let newList = [];
 this.filesLists.forEach((item) => {
  arrs = item.name.split('.');
  suffix = arrs[arrs.length - 1];
  type = item.type ? item.type : item.raw ? item.raw.type : suffix;
  ARR.some(items => {
  if (type.includes(items)) {
  newList.push(item)
  }
  })
 })
 return newList;
 }
 },
 methods: {
 //通過父組件傳入的file獲取當(dāng)前查看的圖片index
 getImgIndex() {
 let that = this;
 that.imgList.forEach((item, index) => {
  if(that.file.id == item.id){
  that.imgIndex = index;
  }
 })
 },
 //隱藏查看圖片
 hideMask() {
 this.$emit('hideMask', false);
 },
 stopEvent(event) {
 //阻止冒泡事件
 //取消事件冒泡
 let e = event; //若省略此句,下面的e改為event,IE運(yùn)行可以,但是其他瀏覽器就不兼容
 if (e && e.stopPropagation) {
  e.stopPropagation();
 } else if (window.event) {
  window.event.cancelBubble = true;
 }
 },
 //上一張
 prevOne() {
 if (this.imgIndex == 0) {
  return false;
 }
 let img = document.getElementById('img')
 img.style.transform = 'rotate(0deg)';
 this.imgIndex = this.imgIndex - 1;
 this.seeAttachment(this.imgIndex);
 },
 //下一張
 nextOne() {
 let listLength = this.imgList.length - 1;
 if (this.imgIndex >= listLength) {
  return false;
 }
 let img = document.getElementById('img')
 img.style.transform = 'rotate(0deg)';
 this.imgIndex = this.imgIndex + 1;
 this.seeAttachment(this.imgIndex);
 },
 //右轉(zhuǎn)
 rotate(t) {
 let img = document.getElementById('img')
 var reg = /(rotate\([\-\+]?((\d+)(deg))\))/i;
 var wt = img.style['-webkit-transform'],
  wts = wt.match(reg);
 var $3 = RegExp.$3;
 var current = $3 ? parseInt($3) : 0;
 if (t == 0) {
  current = current == 0 ? 360 : current;
  current = (current - 90) % 360;
 } else {
  current = (current + 90) % 360;
 }
 img.style.transform = 'rotate(' + current + 'deg)';
 },
 seeAttachment(index = 0) {
 if (this.imgList.length == 0) {
  return false;
 }
 let that = this;
 let basePath = "http://" + (process.env.OSS_PATH.indexOf("test") == -1 ? "opyx-mtds-pro" :
  "opyx-mtds-test") + ".oss-cn-shenzhen.aliyuncs.com/";
 that.imgPath = basePath + that.imgList[index]['path'];
 let img_url = basePath + that.imgList[index]['path'];
 // 創(chuàng)建對象
 var img = new Image();
 // 改變圖片的src
 img.src = img_url;
 // 定時執(zhí)行獲取寬高
 var check = function() {
  // 只要任何一方大于0 
  // 表示已經(jīng)服務(wù)器已經(jīng)返回寬高 
  if (img.width > 0 || img.height > 0) {
  let wdt = document.body.offsetWidth;
  let hgt = document.body.offsetHeight;
  let ratio = 1;
  if (img.width > img.height && img.width > wdt * ratio) {
  img.height = img.height * wdt * ratio / img.width;
  img.width = wdt * ratio;
  console.log('寬大于高', img)
  } else if (img.height > img.width && img.height > hgt * ratio) {
  img.width = img.width * hgt * ratio / img.height;
  if (img.width > wdt) {
  img.width = wdt;
  }
  img.height = hgt * ratio;
  console.log('高大于寬', img)
  } else {
  img.height = img.height * wdt * ratio / img.width
  img.width = wdt * ratio
  console.log('正常', img)
  }
  that.width = img.width;
  that.height = img.height;
  clearInterval(set);
  }
 };
 var set = setInterval(check, 40);
 },
 }
 }
</script>
<style lang="scss" scoped>
 .handleImg_box {
 position: fixed;
 bottom: 0;
 left: 50%;
 z-index: 100;
 margin-left: -150px;
 width: 300px;
 padding: 1rem 0;
 display: flex;
 align-items: center;
 justify-content: space-around;
 }
 
 .handleImg_box div {
 font-size: 0;
 }
 
 .handleImg_box div img {
 width: 3rem;
 }
</style>

補(bǔ)充知識:vue圖片放大、縮小、旋轉(zhuǎn)等。僅需要兩行代碼!??!

效果圖

實(shí)現(xiàn)步驟:

1.下載Viewer組件

npm install v-viewer --save

2.在圖片顯示的頁面引用 viewer組件(一個js文件,一個css樣式文件)

import Viewer from "@/assets/js/viewer.min.js";

import '@/assets/css/viewer.min.css';

3.再需要點(diǎn)擊圖片的標(biāo)簽添加點(diǎn)擊事件@click

<img :id ="item.publicFileURL" :src="item.publicFileURL" @click="aaa(item)" >

說明:因為我的圖片是在集合中存的需要動態(tài)的點(diǎn)擊放大(點(diǎn)哪個放大哪個)----id很重要 aaa()方法中要用

4.@click="aaa(item)"方法

  aaa(item) {
   var viewer = new Viewer(document.getElementById(item.publicFileURL), {
    url: item.publicFileURL,
  });
 },

以上這篇vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 高頻率Vue面試題匯總以及答案

    高頻率Vue面試題匯總以及答案

    vue是組件化開發(fā)框架,所以對于vue應(yīng)用來說組件間的數(shù)據(jù)通信非常重要,下面這篇文章主要給大家介紹了關(guān)于高頻率Vue面試題以及答案的相關(guān)資料,需要的朋友可以參考下
    2023-02-02
  • Vue實(shí)現(xiàn)骨架屏的示例代碼

    Vue實(shí)現(xiàn)骨架屏的示例代碼

    骨架屏就是在頁面數(shù)據(jù)尚未加載前先給用戶展示出頁面的大致結(jié)構(gòu)。本文將利用Vue實(shí)現(xiàn)簡單的骨架屏,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-03-03
  • Vue3源碼分析組件掛載初始化props與slots

    Vue3源碼分析組件掛載初始化props與slots

    這篇文章主要為大家介紹了Vue3源碼分析組件掛載初始化props與slots實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • vue實(shí)現(xiàn)省市區(qū)的級聯(lián)選擇

    vue實(shí)現(xiàn)省市區(qū)的級聯(lián)選擇

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)省市區(qū)的級聯(lián)選擇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 基于ElementUI中Table嵌套實(shí)現(xiàn)多選的示例代碼

    基于ElementUI中Table嵌套實(shí)現(xiàn)多選的示例代碼

    這篇文章主要介紹了基于ElementUI中Table嵌套實(shí)現(xiàn)多選的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Vue中transition單個節(jié)點(diǎn)過渡與transition-group列表過渡全過程

    Vue中transition單個節(jié)點(diǎn)過渡與transition-group列表過渡全過程

    這篇文章主要介紹了Vue中transition單個節(jié)點(diǎn)過渡與transition-group列表過渡全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 淺談vue中所有的封裝方式總結(jié)

    淺談vue中所有的封裝方式總結(jié)

    因為現(xiàn)在vue的流行,vue的各種插件都出來了,我們公司也是使用vue做項目,那么應(yīng)該如何封裝,本文就介紹一下如何封裝,感興趣的可以了解一下
    2021-07-07
  • Vue2?this?能夠直接獲取到?data?和?methods?的原理分析

    Vue2?this?能夠直接獲取到?data?和?methods?的原理分析

    這篇文章主要介紹了Vue2?this能夠直接獲取到data和methods的原理分析,因為methods里的方法通過bind指定了this為new?Vue的實(shí)例
    2022-06-06
  • Vue父子組件通訊的四種方法詳解

    Vue父子組件通訊的四種方法詳解

    父子組件通訊是指在前端開發(fā)的組件化架構(gòu)中,父組件與子組件之間互相傳遞數(shù)據(jù)和觸發(fā)功能的一種機(jī)制,這種機(jī)制使得組件能夠保持獨(dú)立性的同時,也能協(xié)同工作,本文給大家介紹了Vue父子組件通訊的四種方法,需要的朋友可以參考下
    2024-07-07
  • vue頂部菜單欄實(shí)現(xiàn)小結(jié)

    vue頂部菜單欄實(shí)現(xiàn)小結(jié)

    這篇文章主要介紹了vue頂部菜單欄實(shí)現(xiàn)小結(jié),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06

最新評論