1. 新建一個(gè)base64.js 文件
const fsm = wx.getFileSystemManager();
// base64data = base64資源
// name = 文件名
function base64src(base64data, name, cb) {
const time = new Date().getTime();
const filePath = `${wx.env.USER_DATA_PATH}/${name}.${time}.png`;
const buffer = uni.base64ToArrayBuffer(base64data)
fsm.writeFile({
filePath,
data: buffer,
encoding: 'binary',
success() {
cb(filePath);
},
fail() {
return (new Error('ERROR_BASE64SRC_WRITE'));
},
});
};
module.exports = base64src;
2. 引入使用文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-688893.html
import base64src from "@/utils/base64.js"; //
// 模擬一個(gè)請(qǐng)求然后獲取到base64 后賦值給函數(shù)
let parmas = { type: 'test' }
testRequst(parmas).then(res => {
base64src(res, res.schoolId, (res) => {
let img = res // http格式圖片
});
})
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-688893.html
到了這里,關(guān)于uniapp 存儲(chǔ)base64資源為http鏈接圖片的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!