H5 requires the input box to be used when uploading pictures. The type attribute of the input box is set to File, the accept attribute is set to image/*, and the uploaded file type is limited to image. Meanwhile, the data format transmitted to the background is formdata.

Image upload preview function

The image is passed to the back end, which returns the url of the image to the front end, which simply replaces the img SRC.

The method here does not need to go through the back end to implement the preview function