Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V-model directive with computed properties. #17

Closed
amanpatel opened this issue Dec 10, 2015 · 6 comments
Closed

V-model directive with computed properties. #17

amanpatel opened this issue Dec 10, 2015 · 6 comments

Comments

@amanpatel
Copy link

I'm new to the flux pattern. Since components are not supposed to mutate state directly. How would a component designer use v-model directive easily within their app?

@yyx990803
Copy link
Member

See the form handling section: http://vuex.vuejs.org/en/forms.html

@airtonix
Copy link

@yyx990803 that explains box fields (text/number/date/etc) form fields, but not select,radio or checkbox.

<label for="animalDogs">Dags</label>
<input type="radio"
       id="animalDogs"
       name="animal"
       value="dogs"
       :checked="animal === 'dogs'"
       @change="setAnimal">
<select name="animal" 
        @change="setAnimal">
  <option value="dogs"
          :selected="animal === 'dogs'">Dags</option>
  <option value="cats"
          :selected="animal === 'cats'">Cats</option>
</select>
import store from 'app/store';

export default {
  computed: {
    animal () {
       return store.state.animal;
    }
  },
  methods: {
    setAnimal: (type) {
      store.actions.setAnimal(type);
    }
  }
}

Is this about right?

@airtonix
Copy link

nevermind, using this instead:
#38

@PrimozRome
Copy link

@airtonix can you post your exact solution with checkboxes/radio buttons please?

@canmihci
Copy link

really, is there something up with checboxes and radio yet?

@yarsky-tgz
Copy link

You can use https://github.com/yarsky-tgz/vuex-dot for full support of reactive changes on vuex. Checkboxes work too, sure )

Example of simple value changing through incrementing\decrementing:

<template>
  <button @click.stop="step--">back</button>
  <button @click.stop="step++">next</button>
</template>

<script>
  import { takeState } from 'vuex-dot';

  export default {
    computed: {
      step: takeState('wizard.step') 
        .commit('setWizardStep')
        .map()
    }
  }
</script>

store/index.js

export default new Vuex.Store({
  state: {
    wizard: {
      step: 1
    }
  },
  mutations: {
    setWizardStep(state, step) {
      state.wizard.step = step;
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants