生成海报
用的js;
jquery
html2canvas.min.js
html中写上海报主体,生成的时候获取最外层类名,
把生成的海报弹出来
<!-- 海报图片 -->
<van-popup class="posterImg_wrap" v-model="showPoster">
<img :src="posterSrc" alt="">
<p>长按海报保存</p>
</van-popup>
// 生成海报
resultPoster() {
let vm = this;
vm.$toast.loading({
message:"生成中",
duration:0,
})
this.$nextTick(()=>{
let target = document.querySelector('.haibao_l2');
let width = getComputedStyle(target).width.split('px')[0];
let height = getComputedStyle(target).height.split('px')[0];
new html2canvas(target, {
allowTaint: true,
useCORS: true,
scrollX: 0,
scrollY: 0,
width,
height,
}).then(canvas => {
this.posterSrc = canvas.toDataURL("image/jpg");
});
})
},
碰到无法生成换一下插件版本,或者改一下参数

浙公网安备 33010602011771号