search

Home  >  Q&A  >  body text

javascript - What is the correct way to write vuex's mapState to coexist with other computed properties?

The official example usage of mapState is:

computed:mapState(['count'])

How should we write other computed attributes that do not require state? I tried

computed:{mapState(['count']), age(){return this.old_age + 1;}}

will report an error

computed:mapState(['count', age(){return this.old_age + 1;}])

will also report an error, even

computed:{mapState(['count'])}

Will report an error. What is the correct way to write it?

为情所困为情所困2865 days ago938

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:26:52

    Can you read the official vuex documentation before asking?
    computed: { localComputed () { / ... / },
    // Use the object spread operator to mix this object into an external object
    ...mapState({ // ... })
    }
    If you don’t know what the object spread operator is, please check the es6/7 documentation

    reply
    0
  • Cancelreply