[Vuejs]-How do you prepopulate a Vue text field from Vuex state?

0๐Ÿ‘

@Terry you got it! Thanks!

<v-text-field
  v-model.trim="getName">{{ getName }}</v-text-field>

data: () => ({ name: '' })

computed: {
    getName: {
      get: function() {
        return this.$store.state.name
      },
      set: function(newValue) {
        this.name = newValue
      }
    }

methods: {
    submit() {
      if(!this.name) {
        this.name = this.$store.state.name
      } 
      this.$store.dispatch('updateMe', {
        name: this.name,
      });
    }

export default new Vuex.Store({
  state: {
    name: null,
  }

Leave a comment