首页 > Web开发 > 详细

[Mise] Keep a DOM input and state value in sync with the `x-model` directive in Alpine JS

时间:2020-05-14 19:39:11      阅读:59      评论:0      收藏:0      [点我收藏+]

In this lesson, we see how the x-model directive makes achieving "two-way data binding" effortless in Alpine JS.

We see what it would take to recreate the same functionality with an x-bind directive for the input value, as well as an @input event listener which, thanks to an access to the browser‘s native events via the $event magic property, sets the state value to $event.target.value.

 

<div x-data="{name: ‘‘}">
  <label>Your name</label>
  <!-- [(ngModel)] -->
  <input type="text" x-model="name">
  <p>Hi, my name is <span x-text="name || ‘_______________‘"></span>! ??</p>
</div>

 

[Mise] Keep a DOM input and state value in sync with the `x-model` directive in Alpine JS

原文:https://www.cnblogs.com/Answer1215/p/12890664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!