美文网首页
vuex相关笔记

vuex相关笔记

作者: UmustHU | 来源:发表于2018-09-28 14:22 被阅读0次
一个模块中的配置
const state = {
    top_bar_menu: false,
    oldApi: 'http://fawmall.test.vcyber.com/mobile',
    newApi: 'http://fawmall.test.vcyber.com/pointMobile',
    webUrl: 'http://fawmall.test.vcyber.com/point',
    location: {
        lng: '',
        lat: '',
        status: 0
    },
    arr:[1,2,2,3,4]
};

const getters = {
    test(state){
        return state.arr.length
    }
};

const mutations = {
    top_bar_menu_show(state, payload) {
        state.top_bar_menu = payload;
    },
    locate_data(state, payload) {
        state.location = payload;
    }
};

const actions = {};

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}
将各个模块引入集中
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import config from './config'
import shop from './shop'

export default new Vuex.Store({
    modules: {
        config: config,
        shop: shop
    }
})
如何调取state
computed:{
    //方式一
    arr(){
        return this.$store.state.config.arr;
    }
    //方式二,同时引入多个
    ...mapState({
        oldApi: state => state.config.oldApi,
        newApi: state => state.config.newApi,
        webUrl: state => state.config.webUrl
    }),
    //方式三,简化
    ...mapState('config/',{
        oldApi: state => state.oldApi,
        newApi: state => state.newApi,
        webUrl: state => state.webUrl
     }),
    //方式四,如果计算属性和state子节点名称一样,可以简化
    ...mapState('config/',[
        'oldApi',
        'newApi',
        'webUrl'
    ]),
}
如何引入getters
computed:{
    //普通引入方式
    test2(){
        return this.$store.getters['config/test2'];
    }
    //方式二,同时引入多个
    ...mapGetters('config/',{
        test:'test',
        test3:'test3'
    })
}

相关文章

  • vuex相关笔记

    一个模块中的配置 将各个模块引入集中 如何调取state 如何引入getters

  • vuex+axios 的开发流程记录

    相关文档 vuex: https://vuex.vuejs.org/zh/ 是否有必要使用vuex vuex是vu...

  • vuex相关

    1. 从vuex中取的数据,不能直接更改,单向数据流 需要浅拷贝对象之后更改,否则报错; 2. vuex中的数据在...

  • 使用electron实现百度网盘悬浮窗口功能的示例代码

    相关依赖 里面使用了vuex vue vue-route storeJs storeJs 用来持久化vuex状态 ...

  • 如何更丝滑的使用Vuex

    vuex-cuer 简介 还在为 vuex 的魔法字符串而烦恼?还在为阅读项目里 vuex 相关的代码而头痛?如何...

  • uniapp 中 vuex调试

    uniapp中内置了vuex依赖,在微信小程序中为了更方便的调试vuex相关数据,使用vuex中的createLo...

  • vuex相关文章

    vuex模块化和命名空间的实例代码

  • Vuex 相关试题

    1.[判断题]模块化vuex,可以让每一个模块拥有自己的state、mutation、action、getters...

  • 教你快速明白和搭建Vuex工作环境

    vuex工作工作原理(写给自己看的笔记以加深自己的理解) 一、Vuex工作原理 首先我们先来了解下Vuex: 1...

  • vuex学习笔记

    vuex学习笔记 vuex是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存...

网友评论

      本文标题:vuex相关笔记

      本文链接:https://www.haomeiwen.com/subject/fofpoftx.html