Definition and Usage
The onload event occurs when an object has been loaded.
onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).
The onload event can be used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.
The onload event can also be used to deal with cookies (see "More Examples" below).
Syntax
<element onload="myScript"> // in HTML
object.onload = function(){myScript}; // in js
object.addEventListener("load", myScript); // in js, use the addEventListener() method
example:
const { fileBinary } = this.$refs.pCover; // 获取二进制文件 File类型
const reader = new FileReader();
reader.readAsDataURL(fileBinary); // 转base64
reader.onload = () => { // reader load完成后
this.previewImg = reader.result; // 获取img 直接放在src里, 例: <img src="previewImg " />
};