将整个html网页生成图片

<!--
 * @Description: 
 * @Author: 熊成强
 * @Date: 2019-06-25 14:21:15
 * @LastEditTime: 2019-09-27 16:39:54
 * @LastEditors: xcq
 -->
<template>
  <div class="shareParent">
    <div class="share" id="share" ref="share" v-show="firstFlag">
      <div class="share-header">
        <div class="share-header-left">
          <img src="/static/home/header.png" alt />
        </div>
        <div class="share-header-right">
          <span class="share-header-right-zi">179***9064邀请你免费领</span>
        </div>
      </div>
      <div class="share-lq a" style>
        <img @touch.prevent src="/static/share/header.png" alt />
      </div>
      <div class="share-lq">
        <img @touch.prevent src="/static/share/wenzi.png" alt />
      </div>
      <div class="share-lq">
        <img @touch.prevent src="/static/share/hua.png" alt />
        <div class="share-lq-qr">
          <qrcode class="qr" />
          <div class="share-lq-qr-xiazai">扫码下载 Starteos App 钱包</div>
        </div>
      </div>
    </div>

    <img class="show-img" style="width:100%;" :src="dataURL" alt v-show="!firstFlag" />
  </div>
</template>

<script>
import html2canvas from 'html2canvas'
import qrcode from "$com/st/qr"
export default {
  components: { qrcode },
  data () {
    return {
      firstFlag: true,
      dataURL: ''
    }
  },
  async mounted () {
    const that = this
    that.$nextTick(function () {
      setTimeout(() => {
        that.toImg()
        console.log('setTimeout: ');
      }, 5000)
    })

  },
  created () {
    // this.imgSRC = window.location.href
    this.firstFlag = true

  },
  computed: {

  },
  watch: {
  },
  destroyed () {

  },
  methods: {
    toImg () {
      const that = this
      // document.querySelector('#share')
      html2canvas(this.$refs.share).then(canvas => {
        let imgUrl = canvas.toDataURL('image/png');
        console.log('imgUrl: ', imgUrl);
        that.dataURL = imgUrl;
        that.firstFlag = false;
      }).catch(error => {
      })
    },

  }
}
</script>
<style lang="scss">
// @import "./share.scss";
#app {
  .shareParent {
    width: 100%;
    height: 100%;
    overflow: auto;
  }
  .share {
    width: 100%;
    // height: 100%;
    background: url("/static/share/bg.png") no-repeat center;
    background-size: cover;
    &-header {
      box-sizing: border-box;
      width: 100%;
      height: 60px;
      padding: 15px;
      @extend .flex;
      justify-content: flex-start;
      &-left {
        width: 45px;
        height: 45px;
        border-radius: 50%;
        margin-right: 15px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      &-right {
        font-size: 16px;
        color: #fff;
      }
    }
    .a {
      margin-bottom: 65px;
    }
    &-lq {
      width: 100%;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
      &-qr {
        width: 100%;
        @extend .flex;
        flex-direction: column;
        align-items: center;

        position: absolute;
        left: 0;
        right: 0;
        top: 15px;
        margin: auto;
        .qr {
          width: 125px;
        }
        &-xiazai {
          font-size: 12px;
          margin: 6px 0 0 0;
          color: rgba(255, 255, 255, 0.8);
        }
      }
    }
  }
}
</style>

<template>
  <div>
    <vue-qr :logoSrc="imageUrl" :text="codeValue" :logoScale="35" :margin="4" :size="size"></vue-qr>
  </div>
</template>
<script>
import VueQr from 'vue-qr'
export default {
  props: {
    codeValue: {
      type: String,
      default: "https://www.starteos.io/"
    },
    size: {
      type: Number,
      default: 125
    }
  },
  data () {
    return {
      imageUrl: '/static/share/logo.png',//默认二维码中间图片
    }
  },
  components: {
    VueQr
  }
}
 </script>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值