Vuetify: v-select 从 v-for 循环中获取项目和另一个值

huangapple go评论68阅读模式
英文:

Vuetify: v-select get item AND another value from v-for loop

问题

我是你的中文翻译,以下是你要翻译的部分:

"Vuetify3 newbie here.

I have a table which is filled with v-for for some models. Each row has a v-select that need to fire an event when changed. Something like this:

If leave function in @update:modelValue="changeStatus" without any parameters, I can get access to selected value in one v-select.

But how I can get selected value AND id of current row simultaneously?

I was thinking about something like @update:modelValue="changeStatus(item, payout.id)". But of course it doesn't work."

英文:

Vuetify3 newbie here.

I have a table which is filled with v-for for some models. Each row has a v-select that need to fire an event when changed. Something like this:

                <tr v-for="payout in payouts" :key="payout.id">

                    <td>{{ payout.username }}</td>
                    <td>
                        <v-select
                            v-model="payout.status"
                            @update:modelValue="changeStatus"
                            :items="['On', 'Off']"
                        >
                        </v-select>
                    </td>
                </tr>

If leave function in @update:modelValue="changeStatus" without any parameters, I can get access to selected value in one v-select.

But how I can get selected value AND id of current row simultaneously?

I was thinking about something like @update:modelValue="changeStatus(item, payout.id)". But of course it doesn't work .

答案1

得分: 2

"Instead of calling changeStatus directly, I would wrap it in a callback which dispatches the update:modelValue argument AND payout.id:

<tr v-for="payout in payouts" :key="payout.id">
 <td>
  <v-select @update:modelValue="val => changeStatus(val, payout.id)">
 </td>
</tr>

I omitted some code to make it simpler to grasp."

英文:

Instead of calling changeStatus directly, I would wrap it in a callback which dispatch update:modelValue argument AND payout.id:

&lt;tr v-for=&quot;payout in payouts&quot; :key=&quot;payout.id&quot;&gt;
 &lt;td&gt;
  &lt;v-select @update:modelValue=&quot;val =&gt; changeStatus(val, payout.id)&quot;&gt;
 &lt;/td&gt;
&lt;/tr&gt;

I omitted some code to make it simpler to grasp.

huangapple
  • 本文由 发表于 2023年2月8日 23:40:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定