≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

vue实现点击图片放大效果

人气:369 时间:2019-04-07

这篇文章主要为大家详细介绍了vue实现点击图片放大效果,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

本文实例为大家分享了vue点击图片放大展示的具体代码,供大家参考,具体内容如下

1.建立子组件,来实现图片方法功能: BigImg.vue

代码如下:


<template>
  <!-- 过渡动画 -->
  <transition name="fade">
     <div class="img-view" @click="bigImg">
       <!-- 遮罩层 -->
       <div class="img-layer"></div>
       <div class="img">
         <img :src="imgSrc">
       </div>
    </div>
  </transition>
</template>
<script>
  export default {
    props: ['imgSrc'],//接受图片地址
    methods: {
      bigImg() {
      // 发送事件
        this.$emit('clickit')
      }
    }
  }
</script>
<style scoped>
  /*动画*/
  .fade-enter-active,
  .fade-leave-active {
    transition: all .2s linear;
    transform: translate3D(0, 0, 0);
  }
  .fade-enter,
  .fade-leave-active {
    transform: translate3D(100%, 0, 0);
  }
 
  /* bigimg */
  .img-view {
    position: inherit;
    width: 100%;
    height: 100%;
  }
  /*遮罩层样式*/
  .img-view .img-layer {
    position: fixed;
    z-index: 999;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
  /*不限制图片大小,实现居中*/
  .img-view .img img {
    max-width: 100%;
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    margin: auto;
    z-index: 1000;
  }
</style>

2.在父类中使用子组件:

代码如下:


<template xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div class="contents">
    <div class="group">
      <div class="special">
        <span v-text="pagedata.subtitle"></span>
      </div>
      <span class="text-muted" v-text="pagedata.headline"></span>
      <div class="group_img">
        <!-- 放大图片 -->
        <big-img v-if="showImg" @clickit="viewImg" :imgSrc="imgSrc"></big-img>
   
        <div class="text" v-text="pagedata.article"></div>
        <img id="smallImg" :src="pagedata.imgurl" @click="clickImg($event)">
      </div>
    </div>
  </div>
</template>
 
<script>
import BigImg from '../../index/moduleStyles/BigImg.vue';
export default {
  data () {
    return {
      showImg:false,
      imgSrc: ''
    }
  },
  props: ['pagedata'],
  computed: {},
  components: { 'big-img':BigImg},
  methods: {
    clickImg(e) {
      this.showImg = true;
      // 获取当前图片地址
      this.imgSrc = e.currentTarget.src;
    },
    viewImg(){
      this.showImg = false;
    },
  },
  watch: {},
}
</script>
<style>
</style>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持四海网。

本文来自:http://www.q1010.com/184/3942-0.html

注:关于vue实现点击图片放大效果的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • vue动态路由实现多级嵌套面包屑的思路与方法
  • vue.js声明式渲染和条件与循环基础知识
  • vue-cli项目如何使用vue-resource获取本地的json数据(模拟服务端返回数据)
  • Django+Vue.js搭建前后端分离项目的示例
  • 浅谈sass在vue注意的地方
  • Vue.js仿微信聊天窗口展示组件功能
  • 基于Vue实现页面切换左右滑动效果
  • vue页面使用阿里oss上传功能的实例(二)
  • vue页面使用阿里oss上传功能的实例(一)
  • vue教程之toast弹框全局调用示例分析
上一篇:vue绑定设置属性的多种方式(5)
下一篇:vue动态路由实现多级嵌套面包屑的思路与方法
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。