[Vuejs]-How to set the value of v-model to a getter?

0👍

Two mistakes that I see:

  1. Computed property blogById has the exact same name as your Vuex getter blogById. So you might be unintentionaly overwritting your Vuex getter in this component. Change it to getBlogById()
  computed: {
    ...mapGetters({
      blogById: "blogById",
    }),
    blogById() { 
      return this.blogById(this.id);
    },
  },
  1. v-model is read/write, so you’re trying to write to a value that should only be used for reading. Getters are for reading, and mutations are for writing to a variable in Vuex state. Change it to :value="getBlogById.htmlCode" so then it is correct, as then you only read from the getter.
<textarea
 v-model="blogById.htmlCode"
 cols="30"
 rows="10"
 spellcheck="false"
></textarea>

Leave a comment