vuex

Vuex state on page refresh and multiple tabs

流过昼夜 提交于 2019-12-01 04:23:24
问题 In my app i use firebase API for users authentication I save the login status as a boolean value in my vuex state When the user logs in I set the login status to true and using this I hide the login button on the top menu and display the log out button and vice versa when the user logs out. So i use vuex-persisted state to save the state for page refreshes The dafault storage in vuex-persisted state is local storage Instead of saving the state of store on locaal storage i want it to be saved

Is it bad to commit mutations without using actions in Vuex?

不打扰是莪最后的温柔 提交于 2019-12-01 03:23:23
问题 I have been using Vuex for awhile now, and I have always been following the pattern: Components use Actions to commit Mutations to mutate the Store. I thought this was the proper way to do things considering this diagram from the docs: I came across code where people were committing mutations directly in components, and not even creating simple actions which have no purpose other than to trigger mutations. I even found several examples of this in the Vuex docs. I figured since it's used in

vuexjs getter with argument

≡放荡痞女 提交于 2019-12-01 02:13:05
Is there a way to pass parameter into getter of vuex store ? Something like: new Vuex.Store({ getters: { someMethod(arg){ // return data from store with query on args } } }) So that in component I could use <template> <div> <p>{{someMethod(this.id)}}</p> </div> </template> <script lang="ts"> import { mapGetters } from "vuex" export default { props: ['id'], computed: mapGetters(['someMethod']) } } </script> but in vuex first argument is state and second is other getters . Is it possible? One way to do this can be: new Vuex.Store({ getters: { someMethod(state){ var self = this; return function

Vuex怎么用(1)

笑着哭i 提交于 2019-12-01 01:34:01
1. vuex是什么 github站点: https://github.com/vuejs/vuex在线文档: https://vuex.vuejs.org/zh-cn/简单来说: 对应用中组件的状态进行集中式的管理(读/写) 2. 状态自管理应用 state: 驱动应用的数据源view: 以声明方式将state映射到视图actions: 响应在view上的用户输入导致的状态变化(包含n个更新状态的方法) 3. 多组件共享状态的问题 多个视图依赖于同一状态来自不同视图的行为需要变更同一状态以前的解决办法 * 将数据以及操作数据的行为都定义在父组件 * 将数据以及操作数据的行为传递给需要的各个子组件(有可能需要多级传递)vuex就是用来解决这个问题的 4. vuex的核心概念 1). state vuex管理的状态对象它应该是唯一的const state = { xxx: initValue} 2). mutations 包含多个直接更新state的方法(回调函数)的对象谁来触发: action中的commit('mutation名称')只能包含同步的代码, 不能写异步代码const mutations = { yyy (state, data) { // 更新state的某个属性 }} 3). actions 包含多个事件回调函数的对象通过执行: commit(

uni-app聊天室|vue+uniapp仿微信聊天实例|uniapp仿微信App界面

笑着哭i 提交于 2019-12-01 00:24:55
一、介绍 运用UniApp+Vue+Vuex+swiper+uniPop等技术开发的仿微信原生App聊天室|仿微信聊天界面实例项目uniapp-chatroom,实现了发送图文消息、表情(gif图),图片预览、地图位置、长按菜单、红包/钱包、仿微信朋友圈等功能。 二、测试效果 H5 + 小程序 + App端测试效果如下,实测多端效果均为一致。( 后续大图统一展示App端 ) 二、技术选型 编辑器:HBuilder X 技术框架:uni-app + vue 状态管理:Vuex iconfont图标:阿里字体图标库 自定义导航栏 + 底部Tabbar 弹窗组件:uniPop(基于uni-app封装模态弹窗) 测试环境:H5端 + 小程序 + App端(三端均兼容) 高德地图:vue-amap ◆ 顶部导航栏headerBar 顶部导航栏采用的是自定义模式,具体可参看这篇文章: uni-app自定义导航栏按钮|uniapp仿微信顶部导航条 在pages.json里面配置globalStyle,将navigationStyle设为custom时,原生顶部导航栏不显示,这时就能自定义导航栏 "globalStyle": {"navigationStyle": "custom"} ◆ 引入公共样式/组件及全局弹窗 import Vue from 'vue' import App from '.

How to bind input field and update vuex state at same time

徘徊边缘 提交于 2019-11-30 23:48:54
Im coming from a React background and it's simply enough to set your state from a prop and you could call setState({...}) to update the state, so, with vue / vuex, I find it difficult. To simplify: Vuex State name: "Foo bar" Vuex Action addName I can change the state no problem but I need to bind an input field and when change, the state is updated. Think of this as an update form where the user details are already pre-filled and they can change their name. <input @change="addName(newName) v-model="newName" /> I could add a watch to watch for newName and update the state but, I need to pre

Vuex 常规用法

允我心安 提交于 2019-11-30 22:39:38
背景 很多时候我们已经熟悉了框架的运用,但是有时候就是忘了怎么用 所以这里想记下大部分的框架使用方法,方便使用的时候拷贝 一、安装 npm 方式 npm install vuex --save yarn 方式 yarn add vuex 二、vuex 用法 1、引入以及安装 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: {}, getters: {}, mutations: {}, actions: {} }) new Vue({ // 把 store 提供给 store 选项, // Vue 最初实例化的时候将 store 的实例注入到所有的子组件,意味着子组件可以使用 this.$store 调用 store 实例 store }) 2、正常使用 (1)、state (2)、getters (3)、mutations (4)、actions const store = new Vuex.Store({ state: { count: 0, todos: [ { id: 1, done: true }, { id: 2, done: false } ] }, // 是 state 的 computed getters: {

Vuex

末鹿安然 提交于 2019-11-30 19:19:44
哪里有梦,哪里有家,哪里有故事哪里有她,哪里能盛开复制的花 关于Vuex ( 最下方有代码 ) 什么是Vuex、Vuex的概念 1、vuex是对数据的管理者。管理方式是对数据进行集中式管理。 2、可以解决VUE当中的传递繁琐的问题。通过VUEX来对数据进行传值。vuex可以对数据进行共享 (在任何组件当中使用其数据,并且某个组件数据发生变化,相对应的组件也会发生变化。也是双向绑定。) 3、在vuex中必须遵循单项数据流(保证组件不受影响) 4、最好的一种非父子传值的一种方案 5、vuex中存放了所有公用的状态 Vuex单向数据流操作 当组件需要修改state中的数据的时候必须通过dispatch来触发actions里面的方法,actions的每一个方法里面都会有一个 commit方法,用来触发mutations里面的方法, mutations用来修改state中的数据。当mutations里面的方法触发的时候数据 就会发生改变,因为数据是响应式因此组件中的数据也会发生改变 一、 仓库中的数据在某个组件中使用: 因为仓库已经放到vue的实例中通过this是可以使用的,在组件中通过打印this查到里面的数据 渲染(在组件中渲染):{{this.$store.state.数据中的属性名}} render把虚拟DOM渲染为真是DOM 二、 如何修改state中的数据: (遵循单项数据流)

Vue开发之底部导航栏

删除回忆录丶 提交于 2019-11-30 19:06:43
一、导航切换 封装一个公用组件Tabbar,在需要导航页的页面引入组件即可。代码如下: <template> <div class="tabbar"> <!-- 占位容器 --> <div class="placegolder-container"></div> <!-- 底部导航栏 --> <div class="bottom-tabs"> <div class="tabs-item" v-for="(item, index) in tabsList" :key="index" @click="tabsChange(index)" > <img class="tab-icon" :src="tabIndex==index?item.src:item.src1"> <p class="tab-text" :class="tabIndex==index?'active':''">{{item.text}}</p> </div> </div> </div> </template> <script> export default { name: "tabbar", components: {}, data() { return { tabIndex: 0, tabsList: [ { src: require("../../assets/icon/home.png"), src1:

Vue.js面试题整理

我与影子孤独终老i 提交于 2019-11-30 18:09:12
一、什么是MVVM? MVVM是Model-View-ViewModel的缩写。MVVM是一种设计思想。Model 层代表数据模型,也可以在Model中定义数据修改和操作的业务逻辑;View 代表UI 组件,它负责将数据模型转化成UI 展现出来,ViewModel 是一个同步View 和 Model的对象。 在MVVM架构下,View 和 Model 之间并没有直接的联系,而是通过ViewModel进行交互,Model 和 ViewModel 之间的交互是双向的, 因此View 数据的变化会同步到Model中,而Model 数据的变化也会立即反应到View 上。 ViewModel 通过双向数据绑定把 View 层和 Model 层连接了起来,而View 和 Model 之间的同步工作完全是自动的,无需人为干涉,因此开发者只需关注业务逻辑,不需要手动操作DOM, 不需要关注数据状态的同步问题,复杂的数据状态维护完全由 MVVM 来统一管理。 二、mvvm和mvc区别?它和其它框架(jquery)的区别是什么?哪些场景适合? mvc和mvvm其实区别并不大。都是一种设计思想。主要就是mvc中Controller演变成mvvm中的viewModel。mvvm主要解决了mvc中大量的DOM 操作使页面渲染性能降低,加载速度变慢,影响用户体验。 区别:vue数据驱动