Tim Liberty
Tim Liberty

Reputation: 2129

Vue computed syntax error with mapState

I have this code:

 computed: {
      mapState(["appErrors", "user", "profilesFor"]),
      compiledData () {
      return {
        template: `<p>${this.data}</p>`
      }
    }
  }

Basically I am using Vuex and it has mapState but I also want to define my own computed functions so I changed

computed: mapState(["appErrors", "user", "profilesFor"]) --Works

to

computed: {
      mapState(["appErrors", "user", "profilesFor"]),
      compiledData () {
      return {
        template: `<p>${this.data}</p>`
      }
    }
  }

But it doesn't work. How would I fix this issue?

Upvotes: 4

Views: 5365

Answers (1)

user6748331
user6748331

Reputation:

The mapState helper provides an object containing computed getter functions.

Use the spread operator to include each of those functions in your computed object:

computed: {
  ...mapState(["appErrors", "user", "profilesFor"]),
  compiledData () {
    return {
      template: `<p>${this.data}</p>`
    }
  }
}

Upvotes: 9

Related Questions