Vue preview plugin的使用

使用步骤
  • 1.下载vue-preview

    • npm i vue-preview -S
  • 2.导入vue-preview

    • import VuePreview from ‘vue-preview’
  • 3.在vue中使用vue-preview

    • Vue.use(VuePreview)
  • 4.使用vue-preview

    • a.在代码中插入html标签
     <!-- 缩略图 -->
            <div class="thumbs">
                <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
            </div>  
    
    • b. js配置代码
    <script>
    	export default {
    	    data () {
    	      return {
    	        slide1: [
    	          {
    	          /* 一般src和msrc是同一个地址*/
    	            src: '放大图片src',
    	            msrc: '缩略图片的src',
    	            alt: 'picture1',
    	            title: 'Image Caption 1',
    	            w: 600,//放大图片的宽度
    	            h: 400//放大图片的高度
    	          },
    	           {
    	          /*第二个照片*/
    	            src: '放大图片src',
    	            msrc: '缩略图片的src',
    	            alt: 'picture1',
    	            title: 'Image Caption 1',
    	            w: 600,//放大图片的宽度
    	            h: 400//放大图片的高度
    	          }
    	        ]
    	      }
    	    },
    	    methods: {
    	      handleClose () {
    	      //大图转换为小图调用的方法
    	        console.log('close event')
    	      }
    	    }
    	  }
    </script>
    
    
    • c. 配置css代码,注意,必须配置css代码缩略图才有效果
    .thumbs {
        /deep/ .my-gallery {
                    display: flex;
                    flex-wrap: wrap;
                    figure {
                        width: 30%;
                        margin: 5px;
                        img {
                            width: 100%;
                        }
                    }
                }
            }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vant 4 是基于 Vue 的一套移动端轻量级 UI 组件库,而 vue-cropper 是一个用于裁剪图片的组件。如果你想在 Vant 4 中实现移动端头像上传并使用 vue-cropper 进行裁剪,首先需要安装这两个依赖: ```bash npm install vant vant-image-crop @vue/cli-plugin-vuex ``` 然后在项目里引入组件,并在适当的地方使用它: ```html <template> <van-cell v-if="cropping" title="裁剪"> <van-image-crop :src="currentImage" :preview-src="currentImage" :output-width="100" :output-height="100"></van-image-crop> <van-button slot="actions" @click="finishCrop">确定</van-button> </van-cell> </template> <script> import { VanCell, VanImageCrop } from 'vant'; export default { components: { VanCell, VanImageCrop }, data() { return { cropping: false, currentImage: null // 用户选中的原始图片 URL 或者文件路径 }; }, methods: { pickAvatar() { this.$van.camera.open().then((res) => { if (res.type === 'image') { this.currentImage = res.path; this.cropping = true; // 开始裁剪 } }); }, finishCrop() { // 当用户点击确定时,处理裁剪后的图片 // 这里可以将裁剪结果上传至服务器或者保存到本地 console.log('Cropped image:', this.currentImage); this.cropping = false; } } }; </script> ``` 在这个例子中,`pickAvatar` 方法打开相机选择照片,`finishCrop` 方法则是在用户完成裁剪后触发,处理裁剪后的图片。记得根据实际需求替换 `console.log` 和后续的上传逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值