The principle of v-model in vue

In the process of getting started with Vue, I found that the two-way data binding of v-model is very useful. I found out that v-model is just a syntactic sugar. The specific example is as follows

<input v-model="sth">

In fact, he is equivalent to the following:

<input v-bind:value="sth" v-on:input="sth=$event.target.value">

Since html5, every input will trigger the oninput event, so the input content will be bound to sth when input, so the value of sth will be changed

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324692772&siteId=291194637