js动态设置 backgroundImage base64图片不显示问题

bug记录图片格式为base64 如 data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...9oADAMBAAIRAxEAPwD/AD/6AP/Z

解决方案

1、先把base64里面的空格转义

	img = img.replace(/\s/g, encodeURIComponent(' '))

2、使用模板字符串设置backgroundImage

:style="backgroundImage = `url('${img}')`"

 

posted @ 2022-11-17 00:14  土小狗  阅读(1681)  评论(0编辑  收藏  举报