vue-preview vue图片预览插件+缩略图样式

1、安装vue

npm i vue-preview -S

2、main.js中  导入组件ios

//vue-preview 开始
import VuePreview from 'vue-preview';

// defalut install
Vue.use(VuePreview)

//vue-preview 结束

3、代码npm

一、要为缩略图设定样式 ,要在全局样式中设定,以下:axios

/*图片预览 缩略图*/
.preview figure {
  float: left;
  width: 30%;
  height:calc(30vw - 0px);
  margin: 1.5%;
}

.preview figure img {
  width: 100%;
}

二、组件代码:api

<template>
  <div>

      <!--预览-->
      <vue-preview :slides="setPreview()" class="preview"></vue-preview>

  </div>
</template>

<script>

  export default {
      created () {
        let  pid = this.$route.params.id;
        //发送请求
        this.$axios.get('https://www.apiopen.top/satinGodApi?type=3&page=' + pid)
          .then(res=>{
              this.details = res.data.data;
          })
          .catch(console.log)
      },
      data () {
          return {
              details:[],
          }
      },
      methods:{
        setPreview:function () {
          //给预览图设置参数
          this.details.forEach( img => {
            img.src = img.header;
            img.msrc = img.header;
            img.alt = img.top_commentsName;
            img.title = img.top_commentsName;
            img.w = 200;//这是大图的宽
            img.h = 200;
          } )
          return this.details;
        }
      }
  }

</script>

<style scoped>
/*这里的样式没法控制缩略图*/
</style>

4、效果
一、缩略图ide

二、预览图this

相关文章
相关标签/搜索