title: Two-way Computed Property with Vuejs class components
body: <p>Is it possible to use <strong>two-way computed</strong> properties with vuejs when using <strong>class-style components</strong>? In my case, given an app with a simple vuex store, is there a way to bind the store values to a <strong>select</strong> with <code>v-model</code>?</p>
  
  <p>In the <a href="https://vuex.vuejs.org/guide/forms.html" rel="nofollow noreferrer">vuex documentation</a> there is an example for two-way binding:</p>
  
  <pre class="lang-js prettyprint-override"><code>// ...
  computed: {
    message: {
      get () {
        return this.$store.state.obj.message
      },
      set (value) {
        this.$store.commit('updateMessage', value)
      }
    }
  }
  </code></pre>
  
  <p>But I did not get this to work with class components. I tried something like</p>
  
  <pre class="lang-typescript prettyprint-override"><code>private get myvalue(): boolean {
    return store.state.myvalue;
  }
  
  /* Same type of function I would use when using @input one-way binding*/
  private set myvalue(e: Event /* Wrong type for the setter... */) {
    const target: HTMLSelectElement = e.target as HTMLSelectElement;
    const value = target.value;
  
    if (Boolean(value)) {
      store.commit("myvalue", target.value);
    }
  }
  </code></pre>
  
  <p>But this obviously does not work because getters/setters always have the same data type. The type of <code>myvalue</code> is <code>bool</code>, but passing it to both functions does not work as well, because when binding to a <code>select</code> like so
  </p>
  
  <pre><code>&lt;select v-model="myvalue"&gt;
    &lt;option value="false"&gt;No&lt;/option&gt;
    &lt;option value="true"&gt;Yes&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>The setter does not seem to get a value.</p>
  
  <p>I also tried to bind the value to the <code>select</code> manually (like you would do with text-inputs) but using <code>:selected</code> on the <code>select</code> options didn't work (the first option always was selected).</p>