1.安装
npm i vue-canvas-poster --save
2.引入
在main中引入
import VueCanvasPoster from 'vue-canvas-poster'
Vue.use(VueCanvasPoster)
在单页面引入
import { VueCanvasPoster } from 'vue-canvas-poster'
components: {
VueCanvasPoster,
},
3.使用
<div class="content_container">
<vue-canvas-poster v-if="painting.views[0].url" :widthPixels="595" :heightPixels="842" :painting="painting" @success="success" @fail="fail">
</vue-canvas-poster>
<img :src="posterImg" id="mypic">
</div>
painting: {
position: 'relative',
width: '595px',
height: '842px',
background: require('../../assets/images/ewm_bg.jpg'),
views: [
{
type: 'image',
url: "https://www.sunniejs.cn/static/avatar.png",
css: {
position: 'absolute',
right: '30%',
top: '25%',
color: '#000',
background: '#fff',
width: '250px',
height: '250px',
borderWidth: '40px',
borderColor: '#fff',
},
},
],
},
posterImg: "",
// 海报生成
success(src) {
this.posterImg = src
},
//赋值
handleUpdateBg(row) {
this.posterImg = ''
this.painting.views[0].url = row.qrUrl
},
文档说明https://sunniejs.github.io/vue-canvas-poster/#/README