[英]alpine.js - button in loop / click multiple times fired
我是 alpine.js 的新手并且有一个奇怪的行为。 我究竟做错了什么? 按钮操作“removePerson()”总是执行两次。 我不知道为什么?
<template x-for="(person, i) in persons" :key="i">
<div class="mt-3">
<label>Name <span x-text="i"></span></label>
<div class="input-group">
<input type="text" class="form-control" placeholder="Namen eingeben" x-model="person.name">
<template x-if="i <= persons.length">
<div class="input-group-append">
<span class="input-group-text">
<button type="button" @click.prevent="removePerson(i)" class="btn btn-primary">remove</button>
</span>
</div>
</template>
</div>
</div>
</template>
删除模板标签并将元素保留在其中
<template x-if="i <= persons.length">
</template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.