<canvas id="head_canvas_default" style="display: none"></canvas>
<img :src="imgUrl" />
textToImg (name) {
var fsize = 25; // 图片中文字的大小
var fontSize = 60;
var fontWeight = 'bold';
var canvas = document.getElementById('head_canvas_default');
canvas.width = 120;
canvas.height = 120;
var context = canvas.getContext('2d');
context.fillStyle = '#0887FF'; // 图片背景色
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = '#FFF';
context.font = fontWeight + ' ' + fsize + 'px sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText(name, fontSize, fontSize);
return canvas.toDataURL('image/png')
}
this.imgUrl = this.textToImg('文字')