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

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

 更新時間:2020年07月31日 10:04:35   作者:達(dá)大大  
這篇文章主要介紹了vue實現(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運行可以,但是其他瀏覽器就不兼容
 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)等。僅需要兩行代碼?。?!

效果圖

實現(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.再需要點擊圖片的標(biāo)簽添加點擊事件@click

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

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

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

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

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

相關(guān)文章

  • vue-router之實現(xiàn)導(dǎo)航切換過渡動畫效果

    vue-router之實現(xiàn)導(dǎo)航切換過渡動畫效果

    今天小編就為大家分享一篇vue-router之實現(xiàn)導(dǎo)航切換過渡動畫效果,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vscode 插件開發(fā) + vue的操作方法

    vscode 插件開發(fā) + vue的操作方法

    這篇文章主要介紹了vscode 插件開發(fā) + vue的操作方法,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-06-06
  • vue單頁面在微信下只能分享落地頁的解決方案

    vue單頁面在微信下只能分享落地頁的解決方案

    這篇文章主要介紹了vue單頁面在微信下只能分享落地頁的解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • nginx如何配置vue項目history的路由模式(非根目錄)

    nginx如何配置vue項目history的路由模式(非根目錄)

    這篇文章主要介紹了nginx如何配置vue項目history的路由模式(非根目錄),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vuex中使用modules時遇到的坑及問題

    vuex中使用modules時遇到的坑及問題

    這篇文章主要介紹了vuex中使用modules時遇到的坑及問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue.js狀態(tài)管理之Pinia與Vuex詳解

    Vue.js狀態(tài)管理之Pinia與Vuex詳解

    Pinia和Vuex一樣都是是vue的全局狀態(tài)管理器,其實Pinia就是Vuex5,只不過為了尊重原作者的貢獻(xiàn)就沿用了名字Pinia,下面這篇文章主要給大家介紹了關(guān)于Vue.js狀態(tài)管理之Pinia與Vuex的相關(guān)資料,需要的朋友可以參考下
    2023-02-02
  • vue攔截器及請求封裝代碼

    vue攔截器及請求封裝代碼

    這篇文章主要介紹了vue攔截器及請求封裝代碼,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Element el-checkbox-group v-model不支持對象(object)解決方案

    Element el-checkbox-group v-model不支持對象(object)解決方案

    本文主要介紹了Element el-checkbox-group v-model不支持對象(object)解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • vue 使用localstorage實現(xiàn)面包屑的操作

    vue 使用localstorage實現(xiàn)面包屑的操作

    這篇文章主要介紹了vue 使用localstorage實現(xiàn)面包屑的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vue3中實現(xiàn)選取頭像并裁剪

    Vue3中實現(xiàn)選取頭像并裁剪

    這篇文章主要詳細(xì)介紹了在vue3中如何選取頭像并裁剪,文章中有詳細(xì)的代碼示例,需要的朋友可以參考閱讀
    2023-04-04

最新評論

新化县| 大理市| 隆林| 寿阳县| 海伦市| 陇川县| 远安县| 务川| 桂东县| 政和县| 铅山县| 镇平县| 宁夏| 台中县| 阿巴嘎旗| 汝南县| 凤冈县| 墨竹工卡县| 石城县| 运城市| 报价| 和政县| 宝坻区| 宣武区| 漾濞| 宜兰县| 大荔县| 洛扎县| 泸西县| 平阴县| 开江县| 松桃| 四平市| 叙永县| 乌拉特前旗| 交口县| 荃湾区| 孟津县| 瓮安县| 红桥区| 靖江市|