admin管理员组文章数量:1122832
I have a v-checkbox in my vuetify app that is preloaded with some data from the database on load. However, the user can change the model value of this to true or false manually overwriting the data imported by the database. However, I do not know how to target my function I want it to run if its the user that manually changes it. I do not want it to run when the data is first loaded and fills the model.
I have tried using watch but again it will initiate the function on load which I do not want it to do . The change event will also initiate on load data so that doesnt seem to work. Then there is blur which I tried and that does not work because it requires you to click on the item and change it then click somewhere else on the screen which creates a delay when my function should run exactly when its clicked.
My code is as follows:
<v-checkbox
v-model="approvalLanguageModel"
hide-details
color="primary"
label="Check this if the email will include the approval letter (WARNING: Changing this option will overwrite any current edits to the draft email below with the updated email template!)."
@blur="createDraftEmailTemplate()"
/>
Maybe I should just be using click event with my method and call it a day? Does click event always result in model change/ update to component?
I have a v-checkbox in my vuetify app that is preloaded with some data from the database on load. However, the user can change the model value of this to true or false manually overwriting the data imported by the database. However, I do not know how to target my function I want it to run if its the user that manually changes it. I do not want it to run when the data is first loaded and fills the model.
I have tried using watch but again it will initiate the function on load which I do not want it to do . The change event will also initiate on load data so that doesnt seem to work. Then there is blur which I tried and that does not work because it requires you to click on the item and change it then click somewhere else on the screen which creates a delay when my function should run exactly when its clicked.
My code is as follows:
<v-checkbox
v-model="approvalLanguageModel"
hide-details
color="primary"
label="Check this if the email will include the approval letter (WARNING: Changing this option will overwrite any current edits to the draft email below with the updated email template!)."
@blur="createDraftEmailTemplate()"
/>
Maybe I should just be using click event with my method and call it a day? Does click event always result in model change/ update to component?
Share Improve this question edited Nov 21, 2024 at 22:17 yoduh 14.5k2 gold badges20 silver badges33 bronze badges asked Nov 21, 2024 at 21:38 QiuzmanQiuzman 1,68528 silver badges74 bronze badges 01 Answer
Reset to default 1Use @update:model-value
as it's an update event that comes from v-checkbox triggered by a user interaction. If you set the initial value of v-checkbox with some script code, e.g. approvalLanguageModel.value = true
, that won't cause @update:model-value
to run.
<v-checkbox
v-model="approvalLanguageModel"
hide-details
color="primary"
label="Check this..."
@update:model-value="myFunction"
/>
See this Vuetify Playground demo that mocks an API call (using setTimeout) to set the initial value. Notice no console log appears when the initial value is set. Interacting with the checkbox and clicking it is the only way for the function to run.
本文标签: vuejsInitiate a function with vcheckbox when the item is clicked by the userStack Overflow
版权声明:本文标题:vue.js - Initiate a function with v-checkbox when the item is clicked by the user - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307052a1933175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论