0
点赞
收藏
分享

微信扫一扫

代码片段:图片预览、去重

SDKB英文 2022-04-04 阅读 51
vue.js前端

 一、图片预览

import { ImagePreview } from "vant";
setTimeout(() => {
  this.previewImg();
}, 100);
    previewImg() {
      let contentEl = this.$refs.contentRef;
      let imgs = contentEl.querySelectorAll("img");
      let images=[]
      imgs.forEach((element,index) => {
        images.push(element.src)
        element.onclick=function(){
          ImagePreview({
            images,
            startPosition:index
          })
        }
      });
    },

二、去重

    onSearch(val) {
      if(!this.searchText){
        return
      }
      this.searchText = val;
      // 方法一
      // let index=this.searchHistories.indexOf(val)
      // if(index>=0){
      //   this.searchHistories.splice(index,1)
      // }
      // this.searchHistories.unshift(val)
      // 方法二
      // this.searchHistories.unshift(val)
      // this.searchHistories=[...new Set(this.searchHistories)]
      // 方法三
      this.searchHistories.unshift(val)
      this.searchHistories=_.uniq(this.searchHistories)

      this.isResult = true;
      //console.log(this.isResult);
    },
    onCancel() {
      this.$router.back();
    },
举报

相关推荐

0 条评论