We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
该节教程代码可通过npm start运行devServer,在http://localhost:8080/#/index查看效果
代码示例:/lesson21/src/components/Index.vue
首先需要引入map函数:
import { mapState, mapActions, mapGetters } from 'vuex'
在computed中使用mapState:
computed: { ...mapState(['a', 'b']), }
就可以代替这段代码:
computed: { a() { return this.$store.state.a }, b() { return this.$store.state.b }, }
在methods中添加addA和addB的映射
methods: { ...mapActions(['addA', 'addB']), },
等价于:
methods: { addA(n) { this.$store.dispatch('addA', n) }, addB(n) { this.$store.dispatch('addA', n) }, }
在computed中添加count的映射:
computed: { ...mapGetters(['count']) }
computed: { count() { return this.$store.getters.count } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
阅读更多系列文章请访问我的GitHub博客,示例代码请访问这里。
map映射函数
mapState的使用
首先需要引入map函数:
在computed中使用mapState:
就可以代替这段代码:
mapActions的使用
在methods中添加addA和addB的映射
等价于:
mapGetters的使用
在computed中添加count的映射:
等价于:
The text was updated successfully, but these errors were encountered: