[Mise] Update a count state value with the x-on event listener directive in Alpine JS
2021-03-07 00:30
标签:style most -- lis display te pro directive val str In this lesson, we define a "count" state value with the We then display the "count" value in our HTML with the We also hook up buttons with click event listeners with You are not able to access the state outside the outmost div block [Mise] Update a count state value with the x-on event listener directive in Alpine JS 标签:style most -- lis display te pro directive val str 原文地址:https://www.cnblogs.com/Answer1215/p/12890619.htmlx-data
directive provided by Alpine JS. This defines a new scoped component, which can have access to this state.x-text
directive, which updates an element‘s innerText
value.x-on:click
, which allows us to modify the count value as desired.
div x-data="{count: 0}">
button @click="count--">-1button>
button @click="count++">+1button>
p>The current count is strong x-text="count">strong>.p>
button @click="count = 0">resetbutton>
div>
文章标题:[Mise] Update a count state value with the x-on event listener directive in Alpine JS
文章链接:http://soscw.com/index.php/essay/61105.html