首页 > Web开发 > 详细

[Mise] Focus in input field on page load with `x-init` in Alpine JS

时间:2020-05-14 19:43:17      阅读:55      评论:0      收藏:0      [点我收藏+]

In this lesson, we learn how the x-init directive in Alpine JS lets us run a JavaScript expression once the component has initiated.

We see the nuances that allow us to trigger that code before Alpine performs initial DOM updates, or after these updates have been made.

 

the x-init directive lets you run a JavaScript expression when the component is initiated, but before Alpine JS has performed initial updates to the DOM. If you pass x-init‘s callback function, it will wait until the initial DOM updates are made before running.

 

<div x-data="{name: ‘‘}" x-init="() => $refs.nameInput.focus()">
  <label>Your name</label>
  <input x-ref="nameInput" type="text" x-model="name">
  <p>Hi, my name is <span x-text="name || ‘_______________‘"></span>! ??</p>
</div>

 

[Mise] Focus in input field on page load with `x-init` in Alpine JS

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

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