ios - 尝试将图像存储为 base64 并使用它
问题描述
我在网上找到了一段代码,它似乎可以同时工作但不能同时工作。我认为这可能是我缺乏理解,但我似乎无法让它按照我想要的方式工作。
selectPicture() {
let context = imagepicker.create({
mode: "single" // use "multiple" for multiple selection
});
var imageBase64
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
imageSourceModule.fromAsset(selected).then((imageSource) => {
imageBase64 = imageSource.toBase64String("jpg",60);
console.log("Image saved successfully!")
console.log(imageBase64)
console.log("test test") //runs fine
this.image = "~/assets/images/account/camera.png" //cant seem to run
console.log("test test 2")
}).catch(function (e) {
// process error
console.log("got error 1")
});
})
}).catch(function (e) {
// process error
console.log("got error 2")
});
},
在 中imageSourceModule.fromAsset(selected).then((imageSource)
,我试图将 base64 信息保存在另一个变量中,但除了控制台日志字符串之外似乎无法做任何事情。例如,当我运行时this.image = "~/assets/images/account/camera.png"
(只是一个占位符,即使调用一个方法也不起作用),它会捕获一个错误。
问题可能是什么?谢谢你!
更新
我更改console.log("got error 1")
为记录实际更新,我得到的是:
undefined 不是对象(评估 'this.image = "~/assets/images/account/camera.png"')*
我现在认为我对外部调用变量的理解存在问题。我的变量“图像”在脚本中
data() {
return {
image : ""
}
}
解决方案
推荐阅读
- reactjs - 无法在反应中静态分析'require(...,...)'
- ios - 为什么蓝牙经典和 LE 设备在 iOS 上的名称相同?
- angular - Angular 2 - 倒数计时器从分钟切换到秒?
- java - 无法使用 gson 解析 json 输入
- angular - DragulaModel 不使用动态数据
- java - Fxml 中的第二个窗口
- azure-devops - VSTS 扩展任务认证窗口
- mercurial - TortoiseHG 克隆不起作用并验证操作发出警告
- python - 是否可以在 Python 中使用“print”写入剪贴板?
- hyperledger-fabric - 超级账本作曲家休息服务器错误 grep