After I call WeChat's image selection or camera interface to get the localId of the image, can I display the image through <img src=localId>?
If not, how should I display the image?
曾经蜡笔没有小新2017-05-19 10:45:05
Thanks for the invitation, yes. It is available in the WeChat demo. The localid can be displayed directly in src.
PHP中文网2017-05-19 10:45:05
I don’t know if the WeChat interface will work. But the code below will definitely work
<input type="file" accept="image/*" value="点击上传" onchange="preview($event)"/>
<img src="" id="previewImg">
<script>
function preview($event) {
const $target = $event.target
if ($target.files && $target.files[0]){
const reader = new FileReader();
reader.readAsDataURL($target.files[0]);
reader.onload = function(evt){
document.getElementById('previewImg').setAttribute('src', evt.target.result)
// 上传
// 向服务器发送$target.files[0]
}
}
}
</script>