vue列表中小图片放大实现

方式1:

使用element-ui组件库中自带的组件直接进行放大。鼠标移动到其上时,会有单击放大的文字提示。

      <el-table-column label="头像" align="center" width="100px">
        <template slot-scope="scope">
          <el-popover placement="right" trigger="click">
            <div class="row_reserve">
              <img class="big-img" :src="scope.row.face_photo_path" />
            </div>
            <div slot="reference">
              <el-tooltip
                class="item"
                effect="light"
                content="单击放大"
                placement="left"
              >
                <img class="td-img" :src="scope.row.face_photo_path" />
              </el-tooltip>
            </div>
          </el-popover>
        </template>
      </el-table-column>

css部分,就是小盒子和点击之后的大盒子的css样式

.td-img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  padding: 0px;
  margin: 0px;
  cursor: pointer;
  background: transparent;
}
.big-img {
  width: 200px;
  height: 200px;
  border-radius: 10px;
  padding: 0px;
  margin: 0px;
  background: transparent;
}

方式二:

用别人已经写好的轮子,也会比自己写的更加美观,就比如说:使用 v-viewer 组件
第一步,安装
javascript npm install v-viewer --save
第二步:全局引入

import Viewer from 'v-viewer'  //点击图片大图预览
import 'viewerjs/dist/viewer.css'
Vue.use(Viewer)
Viewer.setDefaults({  //默认样式,可以按需求更改
  Options: { 'inline': true, 'button': true, 'navbar': true, 'title': true, 'toolbar': true, 'tooltip': true, 'movable': true, 'zoomable': true, 'rotatable': true, 'scalable': true, 'transition': true, 'fullscreen': true, 'keyboard': true, 'url': 'data-source' }
})

第三步:在表格中去使用

<el-table-column prop="imgPath" label="菜品图片" align="center" header-align="center">
	<template slot-scope="scope">
	  <viewer>
		<img :src="scope.row.imgPath" width="60px" />
	  </viewer>
	</template>
</el-table-column>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现这个功能,你可以使用第三方库来帮助你完成。以下是一个示例,使用了Vue.js和Draggable.js: 1. 首先,使用npm安装Draggable.js:`npm install draggable --save` 2. 在你的Vue组件引入Draggable.js:`import Draggable from 'draggable'` 3. 在Vue组件的mounted()生命周期钩子函数初始化Draggable.js: ```javascript mounted() { const that = this; Draggable.create(this.$refs.popup, { type: 'x,y', bounds: 'body', edgeResistance: 0.65, onClick: function() { that.$emit('popup-click'); } }); } ``` 在这个示例,我们创建了一个可拖动的元素,它的范围限制为整个页面,水平和垂直方向都可以移动。`edgeResistance`属性用于控制拖放边缘的阻力,`onClick`回调函数用于在点击弹窗时触发Vue组件的自定义事件。 4. 为了实现弹窗的放大和缩小功能,你可以使用Vue的动态样式绑定。例如,你可以添加一个按钮来触发放大和缩小: ```html <template> <div ref="popup" class="popup" :style="{ width: width + 'px', height: height + 'px' }"> <div class="popup-header"> <span class="popup-title">{{ title }}</span> <button class="popup-btn" @click="toggleSize">{{ icon }}</button> </div> <div class="popup-body"> <slot></slot> </div> </div> </template> <script> export default { data() { return { title: '弹窗', icon: '放大', width: 400, height: 300 } }, methods: { toggleSize() { if (this.width === 400) { this.width = 800; this.height = 600; this.icon = '缩小'; } else { this.width = 400; this.height = 300; this.icon = '放大'; } } } } </script> ``` 在这个示例,我们添加了一个按钮,通过点击按钮来切换弹窗的大小。我们使用`data`属性来控制弹窗的宽度和高度,当点击按钮时,我们更新这些属性,从而实现弹窗的放大和缩小。 综上所述,你可以使用上述步骤来实现Vue的弹窗可以放大缩小拖放的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值