demand

Limit the number of words entered in a search to 50

The status quo

The select component of ElementUI is used to enter a search mode and trigger a remote request, which is displayed in a drop-down list based on the number of talks. There is a select component in each talk. The input native events are wrapped and not exposed

implementation

General idea:

/ / Mounted/setAttribute(‘ maxLength ‘, ’50’); / / Mounted/setAttribute(‘ maxLength ‘, ’50’);

The problem with this is that you need to do calculations, judgments, loops, wasted performance, code redundancy

Big god idea: Deal with the focus event

SetAttribute (‘ maxLength ‘, ’50’); e.target gets the DOM element. SetAttribute () can be triggered only at Focus to save performance