vue element 多圖片組合預覽

?

定義組件:preview-image

<template><div><div class="imgbox"><divclass="preview-img":class="boxClass"v-if="Imageslist == 3 ||Imageslist == 5 ||Imageslist == 7 ||Imageslist == 8 ||Imageslist >= 9"><divclass="img-box"v-for="(item, index) in imgArr":key="index"><div v-for="(_item, _index) in item" :key="_index"><div class="box-image" v-if="_index <= 3"><el-imageref="preview"fit="cover":preview-src-list="previewImages":src="_item"/><divclass="box-image-shade"@click="imglistclick()"v-if="item.length > 4 && _index == 3"><div class="shade-more"><i class="el-icon-d-arrow-right"></i><iclass="arrow"custom-style="margin-left:-16px;"></i></div><div>{{ Imageslist }}張</div></div></div></div></div></div><div :class="boxClass" class="preview-img" v-else><divv-if="Imageslist != 3 ||Imageslist != 5 ||Imageslist != 7 ||Imageslist != 8 ||Imageslist <= 9"class="box-image"v-for="(item, index) in imgArr":key="index"><el-image fit="contain" :src="item" /> </div></div></div></div>
</template><script>
export default {props: {previewData: {type: Array,default: () => {return [];},//     observer: function (newVal, oldVal) {//         console.log("newVal, oldVal", newVal, oldVal);//         const previewImages = [];//         newVal.map((item) => {//             previewImages.push(item);//         });//         this.setData({//             previewImages,//         });//         this.formatImageList(newVal);//     },},},watch: {previewData: function (newVal, oldVal) {console.log("newVal, oldVal", newVal, oldVal);const previewImages = [];newVal.map((item) => {previewImages.push(item);});this.previewImages = previewImages;this.formatImageList(previewImages);console.log("222222", newVal.length);this.$nextTick(() => {this.Imageslist = newVal.length;});// this.formatImageList(newVal);},},data() {return {previewImages: [],imgArr: [],boxClass: "one",Imageslist: 0,};},mounted() {},methods: {imglistclick() {console.log("圖片", this.$refs.preview[8]);this.$refs.preview[8].clickHandler();},formatImageList(imageArr) {//     console.log("imageArr---", imageArr);console.log("長度:", imageArr.length);const arrLength = imageArr.length;if (arrLength == 1) {// this.setData({//     imgArr: imageArr,//     boxClass: "one",// });this.imgArr = imageArr;this.boxClass = "one";}if (arrLength == 2) {// this.setData({//     imgArr: imageArr,//     boxClass: "two",// });this.imgArr = imageArr;this.boxClass = "two";}if (arrLength == 3) {const firstArr = [...imageArr.splice(0, 1)];const threeArr = [[...firstArr], [...imageArr]];// this.setData({//     imgArr: threeArr,//     boxClass: "three",// });this.imgArr = threeArr;this.boxClass = "three";}if (arrLength == 4) {// this.setData({//     imgArr: imageArr,//     boxClass: "four",// });this.imgArr = imageArr;this.boxClass = "four";}if (arrLength == 5) {const firstArr = [...imageArr.splice(0, 1)];const fiveArr = [[...firstArr], [...imageArr]];// this.setData({//     imgArr: fiveArr,//     boxClass: "five",// });this.imgArr = fiveArr;this.boxClass = "five";}if (arrLength == 6) {// this.setData({//     imgArr: imageArr,//     boxClass: "six",// });this.imgArr = imageArr;this.boxClass = "six";}if (arrLength == 7) {const firstArr = [...imageArr.splice(0, 1)];const secondArr = [...imageArr.splice(0, 4)];const sevenArr = [[...firstArr], [...secondArr], [...imageArr]];console.log("sevenArr", sevenArr);// this.setData({//     imgArr: sevenArr,//     boxClass: "seven",// });this.imgArr = sevenArr;this.boxClass = "seven";}if (arrLength == 8) {const firstArr = [...imageArr.splice(0, 1)];const secondArr = [...imageArr.splice(0, 4)];const eightArr = [[...firstArr], [...secondArr], [...imageArr]];console.log("eightArr", eightArr);// this.setData({//     imgArr: eightArr,//     boxClass: "eight",// });this.imgArr = eightArr;this.boxClass = "eight";}if (arrLength >= 9) {const firstArr = [...imageArr.splice(0, 1)];const secondArr = [...imageArr.splice(0, 4)];const nineArr = [[...firstArr], [...secondArr], [...imageArr]];console.log("nineArr", nineArr);// this.setData({//     imgArr: nineArr,//     boxClass: "nine",// });this.imgArr = nineArr;this.boxClass = "nine";}},},
};
</script><style lang="scss" scoped>
.spanimg {}
.imgbox {width: 675px;padding-bottom: 50px;// background: red;
}
.preview-img {padding: 16px 5px 0;box-sizing: border-box;
}.box-image {margin-top: 10px;width: 315px;height: 315px;border-radius: 6px;overflow: hidden;
}.box-image .el-image {width: 100%;height: 100%;// width: 100px;//     height: 100px;display: block;
}.two {display: flex;align-items: center;justify-content: flex-start;
}.two .box-image + .box-image {margin-left: 12px;
}.three,
.five,
.seven,
.eight,
.nine {display: flex;align-items: center;justify-content: flex-start;
}.three .img-box + .img-box {margin-left: 12px;
}.three .img-box + .img-box .box-image {width: 154px;height: 153px;
}.four {display: flex;flex-wrap: wrap;align-items: center;justify-content: flex-start;
}.four .box-image {width: 205px;height: 205px;margin-right: 14px;margin-top: 14px;
}.five .img-box + .img-box {margin-left: 12px;display: flex;justify-content: space-between;flex-wrap: wrap;
}.five .img-box + .img-box .box-image {width: 153px;height: 153px;
}.six {display: flex;flex-wrap: wrap;align-items: center;justify-content: space-between;
}.six .box-image {width: 205px;height: 205px;margin-top: 14px;
}.seven,
.eight,
.nine {flex-wrap: wrap;
}.seven .img-box:nth-child(2),
.eight .img-box:nth-child(2),
.nine .img-box:nth-child(2) {margin-left: 12px;display: flex;justify-content: space-between;flex-wrap: wrap;width: 315px;
}.seven .img-box:nth-child(2) .box-image,
.eight .img-box:nth-child(2) .box-image,
.nine .img-box:nth-child(2) .box-image {width: 153px;height: 153px;
}.seven .img-box:nth-child(3) {width: 100%;display: flex;align-items: center;justify-content: flex-start;
}.seven .img-box:nth-child(3) .box-image + .box-image {margin-left: 12px;margin-top: 14px;width: 315px;
}.eight .img-box:nth-child(3),
.nine .img-box:nth-child(3) {width: 100%;display: flex;align-items: center;justify-content: space-between;
}.eight .img-box:nth-child(3) .box-image {width: 206px;height: 206px;margin-top: 14px;
}.nine .img-box:nth-child(3) .box-image {width: 152px;height: 152px;margin-top: 12px;position: relative;
}.box-image-shade {width: 152px;height: 152px;position: absolute;top: 0;left: 0;background-color: rgba(0, 0, 0, 0.55);text-align: center;font-size: 28px;font-weight: 500;color: #ffffff;line-height: 42px;padding-top: 36px;box-sizing: border-box;
}
</style>

?父組件中引用子組件preview-image

import previewimage from "../../components/commonModule/preview-image.vue";
 <previewimage :previewData="limagePreviewArn"></previewimage>

data中定義變量:limagePreviewArn?

 this.limagePreviewArn = ["https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg","https://img01.yzcdn.cn/vant/apple-1.jpg","https://img01.yzcdn.cn/vant/apple-2.jpg","https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg","https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg","https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg","https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg","https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg","https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg","https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg","https://img01.yzcdn.cn/vant/cat.jpeg",];

?

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/37617.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/37617.shtml
英文地址,請注明出處:http://en.pswp.cn/news/37617.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

LangChain手記 Models,Prompts and Parsers

整理并翻譯自DeepLearning.AILangChain的官方課程&#xff1a;Models,Prompts and Parsers 模型&#xff0c;提示詞和解析器&#xff08;Models, Prompts and Parsers&#xff09; 模型&#xff1a;大語言模型提示詞&#xff1a;構建傳遞給模型的輸入的方式解析器&#xff1a;…

即時編譯的觸發

文章目錄 Java即時編譯:概述Java即時編譯:原理Java即時編譯:優點提高程序的運行效率動態優化高效利用CPU資源Java即時編譯:案例分析Java即時編譯:概述 Java語言一直是業界公認的高級編程語言,在眾多編程語言中獨樹一幟。Java的JVM(Java虛擬機)是Java語言的核心所在,它…

即將發布的 Kibana 版本可運行 Node.js 18

作者&#xff1a;Thomas Watson Kibana 構建在 Node.js 框架之上。 為了確保每個 Kibana 版本的穩定性和使用壽命&#xff0c;我們始終將捆綁的 Node.js 二進制文件保持為最新的最新長期支持 (LTS) 版本。 當 Node.js 版本 18 升級到 LTS 時&#xff0c;我們開始將 Kibana 升級…

如何理解“對矩陣進行初等行變換不改變其列向量的線性關系”?

對矩陣A進行初等行變換相當于左乘一個可逆矩陣P。 把A看作是列向量組&#xff0c;若有Ax0&#xff0c;則其中的x就說明了列向量的線性關系&#xff1a; [ α 1 , α 2 , α 3 ] [ x 1 x 2 x 3 ] [ 0 ] \left[ \alpha_1 ,\alpha_2, \alpha_3 \right] \begin{bmatrix} x_1\\ x…

【爬蟲】爬取旅行評論和評分

以馬蜂窩“普達措國家公園”為例&#xff0c;其評論高達3000多條&#xff0c;但這3000多條并非是完全向用戶展示的&#xff0c;向用戶展示的只有5頁&#xff0c;數了一下每頁15條評論&#xff0c;也就是75條評論&#xff0c;有點太少了吧&#xff01; 因此想了個辦法盡可能多爬…

【 BERTopic應用 02/3】 分析卡塔爾世界杯推特數據

攝影&#xff1a;Fauzan Saari on Unsplash 一、說明 這是我們對世界杯推特數據分析的第3部分&#xff0c;我們放棄了。我們將對我們的數據進行情緒分析&#xff0c;以了解人們對卡塔爾世界杯的感受。我將在這里介紹的一個功能強大的工具包是Hugging Face&#xff0c;您可以在…

高憶管理:策略:短期利空落地 市場有望企穩回升

高憶管理指出&#xff0c;基于A股商場出資環境分析&#xff0c;尤其是當時商場存量博弈為主的布景下&#xff0c;主張重視以下“21”主線輪動&#xff1a;&#xff08;1&#xff09;國產科技代替立異&#xff1a;電子&#xff08;半導體、消費電子&#xff09;、通信&#xff0…

Vue基本知識

一、vue入門 Vue為前端的框架&#xff0c;免除了原生js的DOM操作。簡化書寫。 基于MVVM的思想&#xff0c;實現數據的雙向綁定&#xff0c;使編程的重點放在數據上。 1、引入vue.js文件 2、定義vue核心對象&#xff0c;定義數據模型 3、編寫視圖 //1、引入vue.js <scr…

關于vue,記錄一次修飾符.stop和.once的使用,以及猜想。

內置指令 | Vue.js 在vue的api里&#xff0c;關于v-on有stop和once兩個事件標簽。 .stop - 調用 event.stopPropagation()。.once - 最多觸發一次處理函數。 原有主要代碼和頁面效果 &#xff08;無stop和once&#xff09;: ...<div class"div" click"di…

激活函數總結(九):Softmax系列激活函數補充(Softmin、Softmax2d、Logsoftmax)

激活函數總結&#xff08;九&#xff09;&#xff1a;Softmax系列激活函數補充 1 引言2 激活函數2.1 Softmin激活函數2.2 Softmax2d激活函數2.3 Logsoftmax激活函數 3. 總結 1 引言 在前面的文章中已經介紹了介紹了一系列激活函數 (Sigmoid、Tanh、ReLU、Leaky ReLU、PReLU、S…

React+Typescript清理項目環境

上文 創建一個 ReactTypescript 項目 我們創建出了一個 React配合Ts開發的項目環境 那么 本文 我們先將環境清理感覺 方便后續開發 我們先來聊一下React的一個目錄結構 跟我們之前開發的React項目還是有一些區別 public 主要是存放一些靜態資源文件 例如 html 圖片 icon之類的 …

響應式設計是什么?怎么學習? - 易智編譯EaseEditing

響應式設計是一種用于創建能夠適應不同設備和屏幕尺寸的網站和應用程序的設計方法。它的目標是確保網站在各種設備上都能提供良好的用戶體驗&#xff0c;無論是在大屏幕的桌面電腦上還是在小屏幕的移動設備上。 在響應式設計中&#xff0c;頁面的布局、字體、圖像和其他元素會…

【yml文件的解釋】

目錄 一、yml的簡介二、手寫yml文件進行配置三、使用yaml格式導出生成模板四、deployment.yaml文件詳解五、Pod yaml文件詳解六、Service yaml文件詳解 一、yml的簡介 Kubernetes 支持 YAML 和 JSON 格式管理資源對象 JSON 格式&#xff1a;主要用于 api 接口之間消息的傳遞 Y…

路由器和交換機的區別

交換機和路由器的區別 交換機實現局域網內點對點通信&#xff0c;路由器實現收集發散&#xff0c;相當于一個獵頭實現的中介的功能 路由器屬于網絡層&#xff0c;可以處理TCP/IP協議&#xff0c;通過IP地址尋址&#xff1b;交換機屬于中繼層&#xff0c;通過MAC地址尋址(列表)…

護眼燈值不值得買?什么護眼燈對眼睛好

想要選好護眼臺燈首先我們要知道什么是護眼臺燈&#xff0c;大的方向來看&#xff0c;護眼臺燈就是可以保護視力的臺燈&#xff0c;深入些講就是具備讓燈發出接近自然光特性的光線&#xff0c;同時光線不會傷害人眼而出現造成眼部不適甚至是視力降低的照明設備。 從細節上看就…

【數據結構】二叉樹篇|『構造二叉樹』刷題

博主簡介&#xff1a;努力學習的22級計算機科學與技術本科生一枚&#x1f338;博主主頁&#xff1a; 是瑤瑤子啦每日一言&#x1f33c;: 所謂自由&#xff0c;不是隨心所欲&#xff0c;而是自我主宰。——康德 目錄 一、前言二、刷題1、最大二叉樹2、從前序與中序遍歷序列構造二…

怎么使用手機遠程控制Win10電腦?

可以使用手機遠程控制電腦嗎&#xff1f; “近期&#xff0c;我將出差一段時間。問題是&#xff0c;我希望能夠從很遠的地方瀏覽家里電腦上的一些東西&#xff0c;但我不會一直隨身攜帶笨重的筆記本電腦。我可以手機遠程訪問Windows電腦嗎&#xff1f; ” 當然&am…

SpringBoot請求響應

簡單參數 1. 原始方式獲取請求參數 Controller方法形參中聲明httpServletRequest對象 調用對象的getParameter參數名 RestController public class RequestController {RequestMapping("/simpleParam")public String simpleParam(HttpServletRequest request){Strin…

Pytorch源碼搜索與分析

PyTorch的的代碼主要由C10、ATen、torch三大部分組成的。其中&#xff1a; C10 C10&#xff0c;來自于Caffe Tensor Library的縮寫。這里存放的都是最基礎的Tensor庫的代碼&#xff0c;可以運行在服務端和移動端。PyTorch目前正在將代碼從ATen/core目錄下遷移到C10中。C10的代…

12-數據結構-數組、矩陣、廣義表

數組、矩陣、廣義表 目錄 數組、矩陣、廣義表 一、數組 二.矩陣 三、廣義表 一、數組 這一章節理解基本概念即可。數組要看清其實下標是多少&#xff0c;并且二維數組&#xff0c;存取數據&#xff0c;要先看清楚是按照行存還是按列存&#xff0c;按行則是正常一行一行的去讀…