# This time I share the problems of image upload and preview encountered in my work

Because we use the weex framework for development (weex is an old and abandoned framework), we do not support some easy-to-use ui libraries such as El ui, which are popular and have rich functions. Therefore, we use the native input (type = file) when solving the problem.

## solve the problem

weex's own eeui library did not find the module for file upload. You have to use native js. Although there will still be type warnings, the function can be completed.

 <input type="file" id="bankCard" @change="saveImg" />


The writing method of html module has not changed, and it is still the normal writing method. Borrowing the change event triggers the methods of saving and uploading pictures.

##### saveImg method defined by methods
saveImg(event) {
let files = event.target.files[0];
if (files === undefined) {
console.log("No pictures selected");
}
const _that = this;
//Event triggered after listening for file reading
const result = e.target.result;
const ele = e.target;
_that.imgSrc[event.target.id] = result;
};
}
},


It should be noted that FileReader is used in this method, which is used to convert images into bs64 format file stream. I choose reader onloadend. After the event, save the file stream to the data of the data component. It's convenient to do picture preview and other desired follow-up functions. Attach the data format in data.

 data: () => ({
imgSrc: {
certificates: "",
bankCard: "",
otherCategories: "",
},
}


Once the file is received, we can start uploading. We tried the formData format here, and there will always be errors. Finally, we decided to use the native ajax to upload.

uploadImg(e) {
var files = e.target.files[0];
console.log("files", files);
func.getUserToken((token) => {
if (token.length > 0) {
}
});
// const  { action } = this;
// let parms = new FormData();
// parms.append("file",files)
let data = {
file: files,
};
//  data = files

console.log("shangchaun", data);
const options = {
action:
data,
onProgress: (e) => {
},
onSuccess: (res) => {
console.log("success", res);
console.log("Is there any at this time files", files);
},
onError: (err) => {},
};
ajax(options);
},


In Ajax (option), you can bring the request header, back-end interface address and some subsequent parameters.
After the upload is successful, you can use the uploaded image bs64 file stream just saved in data to preview the file.

<img
class="hasbankCardImgSrc"
:class="imgSrc.bankCard ? 'bankCardImgSame':''"
:src="imgSrc.bankCard"
/>


Put the corresponding img The corresponding attribute under SRC is bound to the corresponding picture preview position. Of course, I may encounter some other problems in the implementation process. For example, when I encounter the above elements, I will block the input below. My solution is to use the attribute penetration syntax of css3.

CSS3 pointer-events Allow mouse clicks to penetrate subsequent elements
CSS new property pointer-events: Literally, it is a mouse click event, and the values are auto and none.
When used pointer-events:none,Indicates that it will not capture any clicks, but just let the event penetrate below it. The code is as follows:

<style>
.overlay {
pointer-events: none;
}
</style>
<div class="div1">
<div id="overlay" class="overlay"></div>
</div>
//Browser support:
Can see canIUse Data on, currently supported IE11,Firefox3.6+,Chrome,Safari4+,Opera15+,Android,ios.·


Undo: Ctrl/Command + Z
Redo: Ctrl/Command + Y
Bold: Ctrl/Command + B
Italic: Ctrl/Command + I
Title: Ctrl/Command + Shift + H
Unordered list: Ctrl/Command + Shift + U
Ordered list: Ctrl/Command + Shift + O
Checklist: Ctrl/Command + Shift + C
Insert code: Ctrl/Command + Shift + K
Insert link: Ctrl/Command + Shift + L
Insert picture: Ctrl/Command + Shift + G
Find: Ctrl/Command + F
Replace: Ctrl/Command + G

## Creating a reasonable title is helpful to the generation of the directory

Directly input once #, and press space to generate level 1 title.
After entering twice #, and pressing space, a level 2 title will be generated.
By analogy, we support level 6 titles. It helps to generate a perfect directory after using TOC syntax.

## How to change the style of text

Emphasize text emphasize text

Bold text bold text

Tag text

Delete text

Reference text

H2O is a liquid.

The result of 210 operation is 1024

Picture:

Pictures with dimensions:

Centered picture:

Centered and sized picture:

Of course, in order to make users more convenient, we have added the image drag function.

## How to insert a beautiful piece of code

go Blog settings Page, select a code slice highlighting style you like, and the same highlighted code slice is shown below

// An highlighted block
var foo = 'bar';


• project
• project
• project
1. Item 1
2. Item 2
3. Item 3

## Create a table

A simple table is created as follows:

project Value
computer $1600 mobile phone$12
catheter \$1

### The setting content is centered, left and right

Use: ---------: Center
Use: --------- left
Usage -----------: right

First column Second column Third column
First column text centered The text in the second column is on the right The text in the third column is left

### SmartyPants

SmartyPants converts ASCII punctuation characters into "smart" printed punctuation HTML entities. For example:

TYPE ASCII HTML
Single backticks 'Isn't this fun?' 'Isn't this fun?'
Quotes "Isn't this fun?" "Isn't this fun?"
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

## Create a custom list

Markdown Text-to-HTML conversion tool Authors John Luke

## How to create a footnote

A text with footnotes. 1

Markdown converts text to HTML.

## KaTeX mathematical formula

You can render LaTeX mathematical expressions using KaTeX:

Gamma formula display Γ (n)=(n−1)! ∀n∈N\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N Γ (n)=(n−1)! ∀ n ∈ n is through Euler integral

Γ(z)=∫0∞tz−1e−tdt . \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,. Γ(z)=∫0∞​tz−1e−tdt.

## New Gantt chart function to enrich your articles

• For Gantt chart syntax, refer to here,

## UML diagram

UML diagrams can be used for rendering. Mermaid For example, a sequence diagram is generated as follows:

This will produce a flowchart.:

• For Mermaid syntax, refer to here,

## FLowchart

We will still support the flowchart of flowchart:

• For Flowchart syntax, refer to here.

## Export and import

### export

If you want to try this editor, you can edit it at will in this article. When you have finished writing an article, find the article export in the upper toolbar and generate one md file or html file for local saving.

### Import

If you want to load an article you have written md file, you can select the import function in the upper toolbar to import the file with the corresponding extension,