英文:
Vue 3 change event in v-select notwoking
问题
I'm using vue3 and I don't know why I can't watch v-select's change
Can someone help. Thanks a lot
I tried
//test
Ex 1 :<VSelect
v-model="test"
:items="items_status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
item-title="state"
item-value="abbr"
label="Select"
persistent-hint
return-object
single-line
/>
Only v-change works, however it only works when it's changeSelecterStatus()
and not working
with changeSelecterStatus
However if I use v-change="eventMethod()"
it will give me a bunch of events, because when initializing the component it already loads the data change api, so when I do nothing it already runs x2 the total event of the total data I have. And here I use selecter for multiple columns of data generated by for loop so every time I change any selecter it will give me a series of events with the number of executions = total number of selecters on my page
Ex 2: <VCol
v-for="data in datas"
:key="data.id"
>
<VSelect
v-model="data.status"
:items="items_status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus"
item-title="state"
item-value="abbr"
label="Select"
persistent-hint
return-object
single-line
/>
//same
<v-select v-model="data.status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
:items="items_status" item-title="state" item-value="abbr" label="Select" return-object single-line>
<template v-slot:selection="{ item }">
{{ getTextFromCodeStatus(item) }}
</template>
<template #item="{ item, props }">
<v-list-item v-bind="{ ...props, title: undefined }">
{{ item.title }}
</v-list-item>
</template>
</v-select>
changeSelecterStatus: function(){
console.log("task");
},
v-change="changeSelecterStatus()"
-> onload component : return task(data.lenght*2 time)
-> try to choose an option : return task(data.lenght*1 time)
Updated :
seems like v-change can work properly if it can determine the correct data based on data.status and key being its data.id, because of the number times the function is run = number of selectors with v-model="v-model of that selecter"
Ex1 -> load component : return 1 time because 'test' specified at default data does not have to be loaded from the api
英文:
i'm using vue3 and i don't know why i cant watch v-select's change
Can someone help. Thanks a lot
I tried
//test
Ex 1 :<VSelect
v-model="test"
:items="items_status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
item-title="state"
item-value="abbr"
label="Select"
persistent-hint
return-object
single-line
/>
Only v-change works, however it only works when it's changeSelecterStatus()
and not working
with changeSelecterStatus
owever if i use v-change="eventMethod()" it will give me a bunch of events, because when initializing the component it already loads the data change api, so when i do nothing it already runs x2 the total event of the total data I have. And here I use selecter for multiple columns of data generated by for loop so every time I change any selecter it will give me a series of events with number of executions = total number of selecters on my page
Ex 2: <VCol
v-for="data in datas"
:key="data.id"
>
<VSelect
v-model="data.status"
:items="items_status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus"
item-title="state"
item-value="abbr"
label="Select"
persistent-hint
return-object
single-line
/>
//same
<v-select v-model="data.status"
@update:data.status="changeSelecterStatus"
@input="changeSelecterStatus"
@change="changeSelecterStatus"
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
:items="items_status" item-title="state" item-value="abbr" label="Select" return-object single-line>
<template v-slot:selection="{ item }">
{{ getTextFromCodeStatus(item) }}
</template>
<template #item="{ item, props }">
<v-list-item v-bind="{ ...props, title: undefined }">
{{ item.title }}
</v-list-item>
</template>
</v-select>
changeSelecterStatus: function(){
console.log("task");
},
v-change="changeSelecterStatus()"
-> onload component : return task(data.lenght*2 time)
-> try to choose an option : return task(data.lenght*1 time)
Updated :
seems like v-change can work properly if it can determine the correct data based on data.status and key being its data.id, because of the number times the function is run = number of selectors with v-model="v-model of that selecter"
Ex1 -> load component : return 1 tỉme because 'test' specified at default data does not have to be loaded from the api
Ex2
-> onload component : return task(data.lenght*2 time)
-> try to choose an option : return task(data.lenght*1 time)
答案1
得分: 2
根据Vuetify库,我们无法期望触发change事件。
VSelect组件提供@update:modelValue事件来监听选项的修改。
<template>
<v-app>
<VCol v-for="data in datas" :key="data.id">
<VSelect
chips
label="Testing"
v-model="data.status"
:items="data.items"
@update:modelValue="onValueChange"
></VSelect>
</VCol>
</v-app>
</template>
<script setup>
import { ref } from 'vue'
const datas = ref([{id: 1, status: 1, items:[1,2,3]}, {id:2, status: 2, items:[1,2,3]}, {id:3, status: 3, items:[1,2,3]}]);
function onValueChange(v) {
console.log("Value updated ", v)
}
</script>
你可以在下面的Vuetify播放器中找到相同的内容。
英文:
As per the Vuetify library, we couldn't expect a change event to trigger.
VSelect
component offer @update:modelValue event to listen to options modifications.
<template>
<v-app>
<VCol v-for="data in datas" :key="data.id">
<VSelect
chips
label="Testing"
v-model="data.status"
:items="data.items"
@update:modelValue="onValueChange"
></VSelect>
</VCol>
</v-app>
</template>
<script setup>
import { ref } from 'vue'
const datas = ref([{id: 1, status: 1, items:[1,2,3]}, {id:2, status: 2, items:[1,2,3]}, {id:3, status: 3, items:[1,2,3]}]);
function onValueChange(v) {
console.log("Value updated ", v)
}
</script>
You can find same at below Vuetify playground.
答案2
得分: 0
没有本地的 v-change
Vue指令
但它可以工作,因为你有
@change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
它们做相同的事情:@
是 v-on
的快捷方式,所以 @change
= v-on:change
v-change
和 on-change
没有效果,什么也不做。
用以下内容替换所有这些
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
用
@change="changeSelecterStatus"
就足够捕捉到 onChange
事件。
英文:
There is no native v-change
Vue Directive
But it works, since you have
@change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
Which are doing the same thing: @
is a shortcut for v-on
, so @change
= v-on:change
The v-change
and on-change
have no effect and do nothing.
Replace all this
on-change="changeSelecterStatus"
v-on:change="changeSelecterStatus"
v-on:input="changeSelecterStatus"
v-change="changeSelecterStatus()"
with
@change="changeSelecterStatus"
It is enough to catch the onChange
event.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论