Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type for an event in Vue TypeScript project?

What is the correct type for 'e' as in uploadImage function parameter?

public uploadImage(e /* :type of e */){
 const image = e.target.files[0];
 const reader = new FileReader();
 reader.readAsDataURL(image);
 reader.onload = e =>{
    this.previewImage = e.target.result;
    console.log(this.previewImage);
 };
}

In template I have this

<input type="file" accept="image/jpeg" @change=uploadImage>
like image 223
hashan.abeysinghe Avatar asked Mar 13 '19 11:03

hashan.abeysinghe


People also ask

What is event bus in Vue?

An Event Bus is nothing but a global Vue instance that is imported by the components involved in communication and passing data. It makes use of the $on, $emit, and $off properties of the Vue object to emit out events and pass on data.

What type is a Vue component?

Components are reusable Vue instances with custom HTML elements. Components can be reused as many times as you want or used in another component, making it a child component. Data, computed, watch, and methods can be used in a Vue component.

What are custom events in Vue?

Vue takes an approach similar to the HTML DOM events. An element will "emit" an event and the data from that event. This is a robust way to handle custom events because we know that a child component has inputs (props) and outputs (custom events).


1 Answers

The type is just Event. Relevant information is on e.target property.

like image 126
Radu Diță Avatar answered Oct 02 '22 16:10

Radu Diță