Radio and Checkbox Elements v-model Triggers Computed Property Setter
See original GitHub issueWe’re using a checkbox (or radio) form inputs and binding the v-model value to a computed property. The value is passed as prop. We also use a a setter to update that value in the store. After everything is mounted the prop gets updated (via api), which in turn updates the computed property. The problem is when the computed property getter is updated, the setter is triggered.
Here’s a simple example:
export default Vue.component("example", {
template: `
<div>
<b-form-checkbox v-model="value">Label Text</b-form-checkbox>
</div>
`,
props: ['props'],
computed: {
value: {
get: function () { return this.props.value; },
set: function (val) {
this.$store.dispatch('updateValueInStore', val);
}
}
}
});
In this case if the props.value
is updated by the parent the computed property is triggered and then the computed setter is triggered.
I also put together a simple Vue Cli environment/example to mimic the behavior here: https://github.com/ryannmedina/vue-bootstrap-test. This includes a text input, which works as expected.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Computed setter not getting invoked on data change? - Get Help
Trying to implement a checkbox based filter functionality that on change of the checkbox v-model, pushes the array in the model, ...
Read more >How set computed property of checked checkboxes via v ...
vuejs v-model, multiple checkbox and computed property. I've a table with people that have roles, if I want to change the roles I...
Read more >Vue.js Tutorial => Using computed setters for v-model
You might need a v-model on a computed property. Normally, the v-model won't update the computed property value. fiddle Here you would see,...
Read more >v-model not reacting to change on element.selected #345
lazy and a computed property with getter/setter (which is for a currency input). I fixed it with the custom options on the change...
Read more >Using v-model on Nested Vue Components - Zaengle Corp
Form.vue <template> <form> <input name="name" v-model="name"> <input ... Instead, use a data or computed property based on the prop's value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same issue, with version 2.21.2.
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!