【问题标题】:vue send data to server on checkbox changevue 在复选框更改时将数据发送到服务器
【发布时间】:2020-10-03 01:39:58
【问题描述】:

在我的 Vue 模板中,我有以下内容,

<transition-group tag="tbody" name="fade">
    <tr v-for="listing in user.listings" :key="listing.id">
        <td>{{ listing.name | truncate(20) }}</td>
        <td>...</td>
        <td>...</td>
        <td>
            <input type="checkbox" name="active" v-model="listing.active" @change="handleToggleActive" />
        </td>
        <td class="flex direction-row justify-between">
            <button type="button" @click.prevent="handleDelete(listing.id)">Delete</button>
            <router-link :to="`${user.profile.slug}/${listing.slug}/manage`">Edit</router-link>
            <router-link :to="`${user.profile.slug}/${listing.slug}`">View Public</router-link>
        </td>
    </tr>
</transition-group>

当我想要发送一个动作的复选框时,它会向一个 URL 发送一个 PUT 请求,例如,

/api/listing/{id} {id} 是列表的 ID,但我不知道如何从复选框更改事件中获取列表的 ID?这可能吗?

【问题讨论】:

    标签: javascript vue.js


    【解决方案1】:

    只需将参数添加到您的处理程序:

     @change=“handleToggleActive($event, listing.id)”
    

    这是一个很好的总结:pass parameter on v-on

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多