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

基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼

 更新時(shí)間:2019年03月31日 11:11:31   作者:努力的小聰忙  
這篇文章主要介紹了基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

這是一個(gè)簡(jiǎn)單的點(diǎn)擊圖片預(yù)覽的組件

順便記錄一下寫(xiě)組件期間踩的vue中scope的坑~

從注冊(cè)全局組件開(kāi)始叭!

項(xiàng)目目錄:


模仿elementUI目錄結(jié)構(gòu),目錄名是組件名,src中是組件源文件(或者js服務(wù)文件),文件目錄下還有一個(gè)index.js用于同一管理src中的所有文件,導(dǎo)出并注冊(cè),這個(gè)組件我們只有一個(gè)vue文件件

先看index.js文件里有什么:

//引入了src下的vue組件文件
import starPicList from './src/star-pic-list';

/* istanbul ignore next */
starPicList.install = function(Vue) {
  //starPicList.name這就是后面可以使用的組件的名字(star-pic-list.vue文件里面定義的name),install是默認(rèn)的一個(gè)方法
  Vue.component(starPicList.name, starPicList);
};

export default starPicList;

接下來(lái)介紹一下install方法:

Vue.use( plugin ):安裝 Vue.js 插件。如果插件是一個(gè)對(duì)象,必須提供 install 方法。如果插件是一個(gè)函數(shù),它會(huì)被作為 install 方法。install 方法將被作為 Vue 的參數(shù)調(diào)用。當(dāng) install 方法被同一個(gè)插件多次調(diào)用,插件將只會(huì)被安裝一次。Vue.js 的插件應(yīng)當(dāng)有一個(gè)公開(kāi)方法 install 。這個(gè)方法的第一個(gè)參數(shù)是 Vue 構(gòu)造器,第二個(gè)參數(shù)是一個(gè)可選的選項(xiàng)對(duì)象:

導(dǎo)出starPicList組件后在管理組件js文件中引用,然后由這個(gè)統(tǒng)一管理js文件導(dǎo)出注冊(cè)到全局即可:

好了,這些是廢話(huà)!

組件的使用:

<!--圖片列表形式,點(diǎn)擊查看圖片列表,點(diǎn)擊顯示上(下)一張-->
<template v-slot="scope">
  <star-pic-list :data="scope.row.pic" :max-show="2"/>
</template>

參數(shù)
data: 傳入圖片數(shù)組;
max-show: 一次最多顯示幾張圖片

效果如下:

補(bǔ)充:vue組件開(kāi)發(fā)中 style 添加scoped后,修改第三方組件樣式?jīng)]有效果問(wèn)題:

在vue的開(kāi)發(fā)中,我們通常和element-UI配合開(kāi)發(fā),就會(huì)遇到,在組件style中添加scoped后,element-ui中使用的子組件樣式無(wú)法改變。

不用scoped,去掉這個(gè)屬性,但是會(huì)污染全局樣式,(可配合less 或者 scss(推薦scss),所有樣式寫(xiě)在當(dāng)前組件id或class下面)

組件源碼:

<template>
  <div id="star-pic-vue">
    <template v-if="data">
      <img v-for="item in images"
         :src="item"
         id="contract_url"
         @click="enlargePic"/>
      <template v-if="isDialogShow">
    </template>
      <el-dialog
        :visible.sync="centerDialogVisible"
        modal
        close-on-click-modal
        custom-class="dialog"
        >
        <el-carousel :autoplay="false" arrow="always">
          <el-carousel-item v-for="item in data" :key="item">
            <img :src="item">
          </el-carousel-item>
        </el-carousel>
      </el-dialog>
    </template>
  </div>
</template>

<script>
  export default {
    name: "star-pic-list",
    props: ["data","maxShow"],
    data(){
      return{
        centerDialogVisible: false,
        showPic: '',
        isDialogShow: false,
        index: 0,
      }
    },
    computed: {
     images() {
       if (this.data instanceof Array && this.data.length > 2) {
         return this.data.splice(0,this.maxShow)
       } else {
         return this.data
       }
     }
    },
    methods: {
      // 放大圖片
      enlargePic(e){
        this.isDialogShow = true;
        this.centerDialogVisible = true;
        this.showPic = this.data[0];
        console.log(this.images)
      },
    }
  }
</script>

<style lang="less">
#star-pic-vue{
  width: 200px;
  height: auto;
  display: flex;
  flex-wrap: wrap;
  img{
    width: 80px;
    height: 80px;
    margin: 4px;
  }
  .dialog {
    img{
      width: 100%;
      height: 100%;
      margin: 0;
    }
  }
  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
    height: 100%;
    width: 100%;
  }
  .el-dialog__header{
    display: none;
  }
  .el-dialog__body {
    padding: 0 !important;
    margin: 0 !important;
    height: 600px;
  }
  .el-carousel{
    height: 100%;
  }
  .el-carousel__container {
    height: 100%;
  }
}
</style>

更多組件點(diǎn)擊這兒 --> link : github>components>star-pic-list

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

咸宁市| 合水县| 民丰县| 梧州市| 临桂县| 瓦房店市| 毕节市| 延边| 射阳县| 福鼎市| 封丘县| 于都县| 苍南县| 朝阳市| 台中市| 湘潭县| 呼伦贝尔市| 蒙城县| 紫云| 黔西县| 资兴市| 城步| 景德镇市| 安福县| 石林| 淮滨县| 布尔津县| 修文县| 德令哈市| 阜新市| 石柱| 永昌县| 疏附县| 都安| 肥西县| 红安县| 大余县| 德清县| 浦城县| 安新县| 金塔县|