状态管理工具vuex的基本使用(vuebus的理解)

vuex的展示图

在这里插入图片描述

1. vuex 的基本结构

const store = new Vuex.Store({state: {} //相当于 vue结构中的 data getters: {}, // 相当于vue结构中的计算属性使用actions: {}, // 相当于vue结构中的监听属性使用mutations: {},//相当于vue结构中的 methods 方法集合 (其中方法第一个参数为vuex的参数,第二个为调用时传递的参数 )modules:{} //  其中客包含另一个vuex 存在,相当大的模块包
})

1.1 vuex 数据持久化设置

数据持久化设置:

2. vuex 的基本使用

import Vue from 'vue'
import Vuex from 'vuex'
import router from '@/router/router.js'Vue.use(Vuex)export default new Vuex.Store({state: {// isOpen: localStorage.getItem("EP_ADMIN_isOpen") == 'true' ? true : false,// isFixed: localStorage.getItem("EP_ADMIN_isFixed") == 'true' ? true : false,isOpen: true,isFixed: true,querylogoimg:"",},mutations: {setIsOpen(state, val) {state.isOpen = vallocalStorage.setItem("EP_ADMIN_isOpen", val)},setIsFixed(state, val) {state.isFixed = vallocalStorage.setItem("EP_ADMIN_isFixed", val)},logocahnge(state , value){// console.log(value);state.querylogoimg = value},},actions: {},modules: {}
})

3. vuex 的页面使用

<script>
import { mapMutations, mapState } from "vuex"
import Api_login from "@/assets/api/login"
export default {data() {return {username: '',// querylogoimg:"",Defaultlogo:require("../../assets/img/login/logo-headportrait.png"),}},computed: {...mapState([ 'isOpen',  'isFixed'])},created() {},mounted() {this.getUserInfoFun(); // 获取登录者用户信息},methods: {...mapMutations(['setIsOpen', 'setIsFixed' , 'logocahnge' ]),getUserInfoFun(){// this.querylogoimg = let _this = this;// 获取用户信息Api_login.getUserInfo().then(res => {if (res.success) {this.username = res.result.name;// 存储头像图片信息this.$store.commit('logocahnge' ,  res.result.avator)let jsonData = JSON.stringify(res.result);_this.$store.commit("setUserInfo", jsonData);utils.init(this);}});},}
}
</script>也可在 DOM 结构上使用:
<img :src="$store.state.querylogoimg == null ? Defaultlogo : $store.state.querylogoimg" alt="">

最后说下 vuex 中 的 modules

1. 取文件夹中其中一个做代表

在这里插入图片描述

2.文件夹结构使用方式

在这里插入图片描述
vuebus使用描述推荐:https://blog.csdn.net/qq_41630382/article/details/84100016?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162813297116780264087097%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=162813297116780264087097&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-84100016.pc_search_result_control_group&utm_term=vue+bus%E4%BD%BF%E7%94%A8&spm=1018.2226.3001.4187

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/247811.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Memcache

前戏 Memcached是一个高性能的分布式内存对象缓存系统&#xff0c;用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象减少读取数据库的次数&#xff0c;从而减小数据库的压力&#xff0c;提高动态&#xff0c;数据库网站的速度。Memcached基于一个存储 键/值对的…

解决Button自动刷新页面的问题

一、问题 <button class"am-btn am-btn-default am-btn-xs am-text-secondary" data-id"99" data-type1><span class"am-icon-pencil-square-o"></span>修改</button>11 页面上有这样一个按钮&#xff0c;每次点击这个…

Django.1

Django官方网站&#xff1a;https://www.djangoproject.com/ 使用终端创建Django文件 创建工程 django-admin startproject XXX 创建应用 python manage.py startapp YYY 迁移系统指令&#xff1a; 首先生成迁移文件 python manage.py makemigrations 执行迁移文件 python ma…

vue项目水印添加

import DomSize from wd-domsize-monitor; // 此处为 npm 下载的第三方模块包 import Api_login from "/assets/api/login" // 此处是用户信息接口调用var id shuiyinDiv var isInit false let callback function (ele) {DomSize.bind(ele, function () {//水印被…

mybatis传参

在mybatis的学习中&#xff0c;会发现经常需要传参&#xff0c;这里以上一节写的实体类为基础&#xff0c;当我们要添加一个员工时&#xff0c;需要添加员工的基本信息&#xff0c;以及所属部门&#xff0c;按照以前的方法&#xff0c;在实体类中&#xff0c;添加部门id属性&am…

自定义步骤条

展示图&#xff1a; <template><div classcreateorder><!-- 顶部步骤条 --><div class"createorder_top"><div class"createorder_top_left"><!-- 0 --><span class"createorder_left_set" :class"…

jquery让页面滚动到底部

function scrollToEnd(){//滚动到底部var h $(document).height()-$(window).height();$(document).scrollTop(h); }

迭代器

一、定义 1.iterator.(迭代器&#xff09; 2.iterable.&#xff08;可迭代的&#xff09; 一般来说&#xff0c;可以被for循环的就是可以迭代的&#xff0c;迭代器一定可以迭代&#xff0c;但是可迭代的类型不一定是迭代器。 二、说明 1.有__iter__方法&#xff0c;说明可迭代 …

css获取到指定元素的宽度,在回调返回宽度值

<script type"text/javascript">//获取到指定元素的宽度&#xff0c;在回调返回宽度值//通过处理这个value&#xff0c;重新设置新的宽度$(.sixth).css("width",function(index,value){//value带单位&#xff0c;先分解value value.split(px);//返回…

android 文件读写

读取&#xff1a; public static String _getJsonString(String fileName) throws IOException { if ((fileName null) || fileName.isEmpty()) { return ""; } String retString ""; FileInputStream fis null; String state Environment.getExternal…

element组件库中table自定义分页效果

1.在data中设置初始值 // 页数 页码search: { offset: 1, // 当前页limit: 10, // 条数total:0, //总数},2.设置获取后的数据分配 :data"tableData.slice((search.offset - 1) * search.limit, search.offset * search.limit)" 3.展示效果&#xff1a;

Django信号量

信号 Django中提供了“信号调度”&#xff0c;用于在框架执行操作时解耦。通俗来讲&#xff0c;就是一些动作发生的时候&#xff0c;信号允许特定的发送者去提醒一些接受者。 1、Django内置信号 1 Model signals2 pre_init # django的modal执行其构造方…

uni-app 调用接口封装文档

1.创建 util 文件夹 &#xff0c;并在文件夹中创建 api.js const BASE_URL http://localhost:8082 // 域名头 export const myRequest (options)>{return new Promise((resolve,reject)>{uni.request({url:BASE_URLoptions.url,method: options.method || GET,data: …

HTML中INPUT type=date标签如何赋值注意问题

现在的html5 input标签支持type"date" 显示有日期的日历控件&#xff0c;一行简单的代码就能显示出一个日历控件&#xff0c;但是有的时候需要给它一个默认的日期值&#xff0c;这个时候可能就要用到val()&#xff0c; attr("value","")等方法&a…

数据轮播图翻页封装(左右点击)

效果图&#xff1a; <template><div class"box" style"height:200px;"><!-- 左 --><div class"box-left" click"submitrote(left)" mouseenter"chenge_menu(1)" mouseleave"chenge_menu(2)"…

jquery自动点击按钮

jquery自动点击按钮$(document).ready(function(){$("#imgcode_img").trigger("click");});

087-把PHP数组中的元素按随机顺序重新排列shuffle

<?php$arrarray(3,23,A,f,123,hello); //定义一个数组echo 排序之前的数组信息&#xff1a;<br>;print_r($arr);shuffle($arr); //对数组进行随机排序echo <br>排序之后的数组信息&#xff1a;<br>;print_r($arr); //输出数组信息#…

highcharts图表高级入门之polar:极地图的基本配置以及一些关键配置说明

highcharts图表组件内的极地图polar的实现和效果都还是很简单和美观的。 1、需要设置chart的polar属性为true&#xff1b;以表示是极地图&#xff1b; 2、其他的设置和普通图表就没什么区别了的&#xff0c;这里附上一个完整的示例代码&#xff1a; highcharts图表组件内的极地…

基于Element ui 实现输入框只能输入数字并支持千分位

实现效果 设置子组件 <template><el-inputref"money"v-model.trim"money":placeholder"placeholder"v-bind"$attrs"v-on"$listeners"input"formatNumber(money,money)"keyup.enter.native"moneyCh…

Vue-使用webpack+vue-cli搭建项目

一、准备 安装NodeJs 安装Webpack 配置环境变量 技巧使用&#xff1a; 1. npm 淘宝路径配置&#xff1a;npm config set registryhttps://registry.npm.taobao.org  2.查看npm命令列表 > $ npm help 二、搭建项目 1、全局安装vue脚手架工具 vue-cli npm install vue…