1、下载image-tools插件并安装
npm i image-tools --save-dev
2、引入image-tools
import { pathToBase64, base64ToPath } from 'image-tools'
3、将图片转换成base64格式
create() {// 图片转化为base64格式pathToBase64('/static/logo.png').then(res=> {console.log(res); })
}async create() {// 图片转化为base64格式const res = await pathToBase64('/static/logo.png');console.log(res)
}
以上两种方法都可以