问题:vuex分模块后,一个模块如何拿到其他模块的state值,调其他模块的方法?
思路:
1.通过命名空间取值--this.$store.state.car.list // OK
2.通过定义该属性的getter方法,因方法全局注册,不存在命名空间,可以通过this直接调用。
this.$store.state.car.carGetter
我在car模块中自己的定义了state, getters,
this.$store.state.car.list可以拿到值.
但是,this.$store.state.car.carGetter报错,
请问.如何在组件中调用这个getters,
//car.js state = { list: [] } getters = { carGetter: state => { return state.list.filter(''); } } new Vuex.Store({ getters: { test: state => { return '02'; } }, modules: { car } }) // 组件 this.$store.state.car.list // OK this.$store.state.car.carGetter // undefined this.$store.state.carGetter // 为什么这么用ok, 难道会把模块中的getters注册到root "color: #ff0000">补充知识:vuex使用模块的时候 获取state里的数据语法普通语法
this.$store.state.【哪个数据】
模块化语法:
this.$store.state.【哪个模块】.【哪个数据】
<template> <div class="panel panel-info"> <div class="panel-heading"> <h4 class="panel-title">购物车列表</h4> </div> <div class="panel-body"> <p v-if="!CartList.length">这里什么都没有,请先添加商品。</p> <CartListItem v-for="ele in CartList" :key="ele.id" :cartlist-iteam="ele"/> </div> <div class="panel-footer"> <a href="" class="btn btn-block btn-danger">清空购物车({{cartQuantity}})</a> <a href="" class="btn btn-block btn-info">立即结算({{cartTotal}})</a> </div> </div> </template> <script> import CartListItem from './CartListItem' import { mapGetters } from 'vuex' export default { name: 'CartList', components: { CartListItem }, computed: { CartList () { return this.$store.state.cartModule.updateCartList }, ...mapGetters(['cartQuantity', 'cartTotal']) } } </script>以上这篇vuex分模块后,实现获取state的值就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[FLAC/分轨][251.78MB]
- 黄韵玲2001-巴结音乐[全员集合][WAV+CUE]
- 郑绪岚2015-流金岁月·精选[首版][WAV+CUE]
- 周冰倩1995《沧桑情歌》JVC日本录制[WAV+CUE]
- 辛禄乐队.2024-热烈的少年【星辰】【FLAC分轨】
- 成龙.1996-龙的心【滚石】【WAV+CUE】
- 童安格.1991-一世情缘【宝丽金】【WAV+CUE】
- 韩红2010-擦肩而过[央金玛][WAV+CUE]
- RiccardoTesi-UnballoLiscio,Vol.II(2024)[24-48]FLAC
- 金池VS刘罡2009《双声情》[WAV+CUE]
- 冯奥迪《卄》[320K/MP3][67.08MB]
- 冯奥迪《卄》[FLAC/分轨][172.46MB]
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】