推薦一款Vue 生成海報的插件vue-canvas-poster

簡單粗暴,無需多想!!

1.npm 安裝vue-canvas-poster

npm i vue-canvas-poster --save
  1. 在main.js 中引入:
import VueCanvasPoster from 'vue-canvas-poster'
Vue.use(VueCanvasPoster)
  1. 在需要生成海報的頁面使用:
<template>
  <div>
    <vue-canvas-poster :widthPixels="0" :painting="painting" @success="success" @fail="fail"></vue-canvas-poster>
  </div>
</template>
  data() {
    return {
      painting: {
        width:`${document.documentElement.clientWidth}px`,
        height:`${document.documentElement.clientWidth*1.777}px`,
        background: '#f4f5f7',
        views: [
          {
            type: 'image',
            url: require('../../assets/XzyRescources/vipBg.png'),
            css: {
              width:`${document.documentElement.clientWidth}px`,
              height:`${document.documentElement.clientWidth*1.777}px`,
              top: '0'
            }
          },
          {
            type: 'image',
            url: require('../../assets/XzyRescources/userImg.png'),
            css:{
              width:`${document.documentElement.clientWidth/3.5}px`,
              height:`${document.documentElement.clientWidth/3.5}px`,
              top:`${document.documentElement.clientWidth/5.5}px`,
              left: `${document.documentElement.clientWidth/2.8}px`,
            }
          },
          {
            type: 'qrcode',
            content:'19263',
            css: {
              top: `${document.documentElement.clientWidth/1.25}px`,
              left: `${document.documentElement.clientWidth/3.7}px`,
              color: '#333',
              width: `${document.documentElement.clientWidth/2.1}px`,
              height: `${document.documentElement.clientWidth/2.1}px`
            }
          },
          {
            type: 'text',
            text: '兜兜里裹糖@',
            css: [
              {
                top:`${document.documentElement.clientWidth/2}px`,
                left: `${document.documentElement.clientWidth/2.7}px`,
                color:'rgba(52,52,52,1)',
                fontSize: '17px'
              }
            ]
          },
          {
            type: 'text',
            text: '- 長按保存二維碼 -',
            css: [
              {
                top:`${document.documentElement.clientWidth*1.5}px`,
                left: `${document.documentElement.clientWidth/3}px`,
                color:'rgba(52,52,52,1)',
                fontSize: '17px'
              }
            ]
          },
        ],
      },
      img:'',
    }
  },
  methods:{
    success(src) {
      this.img=src
    },
    fail(err) {
      console.log('fail', err)
    },

  }

效果圖:
1598867457(1).jpg

本文鏈接:https://blog.csdn.net/inmarry/article/details/105552070

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容