Vue-preview,找不到open等报错解决

Vue-preview,找不到open等报错解决

由于是大部分学习的是老版本,而现在已经改为新版本,则会报错

1.配置

import Vuepreview from 'vue-preview'
Vue.use(Vuepreview)

2.使用

 <div class="thumbs">
        <vue-preview :slides="photolist" @close="handleClose"></vue-preview>    
      
        </div>

在新版本中,需要使用 vue-preview 并且在 :slides后面是你的数据数组

if(data.status === 0){
                data.message.forEach(item => {
          item.w = 600;
          item.h = 400;
          item.msrc = item.src;
        });

改动最大的,则是item.msrc = item.src 把你遍历的图片地址赋值给item.msrc,则能够遍历出你的图片

handleClose () {  //可以选择加上这个方法
                console.log('close event')
            }

这个方法可加可不加

最后改变CSS

.thumbs{
         /deep/ .my-gallery{   //deep深层作用选择器
              display: flex;
              flex-wrap:wrap;//默认换行
              figure{
                  width: 30%;  
                  margin: 5px; 
                  img{
                      width: 100%;
                      box-shadow: 0 0 8px #999;  
                      border-radius: 5px;
                  }
              }
          }
        }

一定要加深层作用器 或者 去除scoped 否则图片样式得不到改变

最后附上整个源码

<template>
    <div class="photo">
        <h1 class="title">{{ photoinfo.title }}</h1>
        <p  class="info">
        <span>发表时间:{{ photoinfo.add_time | dateFormat}}</span>
        <span>点击册数:{{photoinfo.click}}</span>
        </p>
        <hr>

       <div class="thumb-img-list">
      <!-- 使用 v-for 循环渲染缩略图 -->
      <div class="thumbs">
        <vue-preview :slides="photolist" @close="handleClose"></vue-preview>    
      
        </div>


    </div>

    <div class="content" v-html="photoinfo.content"></div>
        <comment :newsid="id"></comment>
        
    </div>
</template>

<script>
import comment from '../sub-conponents/Comment.vue'
// import mui from '../../../lib/mui/js/mui.previewimage.js'
// import '../../../lib/mui/js/mui.zoom.js'
export default {
    data(){
        return {
            photoinfo:{},
            photolist:[]
        };
    },
    created(){
        this.getPhotoinfo()
        this.getThumbimg()
    },
    methods: {
        async getPhotoinfo(){
            const {data} = await this.$http.get('/api/getimageInfo/'+this.id)
            if(data.status === 0) return this.photoinfo = data.message[0]
        },
        async getThumbimg(){
            const {data} = await this.$http.get('/api/getthumimages/'+this.id)
            if(data.status === 0){
                data.message.forEach(item => {
          item.w = 600;
          item.h = 400;
          item.msrc = item.src;
        })
            this.photolist = data.message
            }
            
        },
         handleClose () {  //加上这个方法
                console.log('close event')
            }
       
        
    },
    
     props: ["id"],
  components: {
    comment
  }

}
</script>


<style lang="scss" scoped>
    .title{
        font-size: 15px;
        text-align: center;
        margin:10px 0;
        color:blue;
    }
    .info{
        font-size: 12px;
        display: flex;
        justify-content: space-between;
    }
    .photo{
        padding:3px;
    }
    .thumb-img-list{
        img{
            width: 100px;
        }
    }
    .thumbs{
         /deep/ .my-gallery{   //deep深层作用选择器
              display: flex;
              flex-wrap:wrap;//默认换行
              figure{
                  width: 30%;  
                  margin: 5px; 
                  img{
                      width: 100%;
                      box-shadow: 0 0 8px #999;  
                      border-radius: 5px;
                  }
              }
          }
        }

</style>

最后就能成功的显现出来啦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值