question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Radio and Checkbox Elements v-model Triggers Computed Property Setter

See original GitHub issue

We’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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
belluzjcommented, Oct 7, 2021

I have the same issue, with version 2.21.2.

0reactions
stale[bot]commented, Apr 16, 2022

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found