vuex

vuex入门文档

a 夏天 提交于 2020-02-08 19:55:44
如果你在使用 vue.js , 那么我想你可能会对 vue 组件之间的通信感到崩溃 。 我在使用基于 vue.js 2.0 的UI框架 ElementUI 开发网站的时候 , 就遇到了这种问题 : 一个页面有很多表单 , 我试图将表单写成一个单文件组件 , 但是表单 ( 子组件 ) 里的数据和页面 ( 父组件 ) 按钮交互的时候 , 它们之间的通讯很麻烦 : <!--父组件中引入子组件--> <template> <div> <a href="javascript:;" @click="show = true">点击</a> <t-dialog :show="show" @dialog_event="hide_dialog"></t-dialog> </div> </template> <script> import dialog from './components/dialog.vue' export default { data(){ return { show:false } }, methods:{ //收到子组件的消息 , 改变show的值 hide_dialog(){ this.show = false; } }, components:{ "t-dialog":dialog } } </script> <!--子组件--> <template> <el-dialog

vuex do not mutate vuex store state outside mutation handlers

[亡魂溺海] 提交于 2020-02-08 10:57:25
问题 [vuex] do not mutate vuex store state outside mutation handlers. When trying to edit the fields this message is shown in the terminal. How do I use the form correctly? <q-editor v-model="form.email" min-height="5rem" /> - data() { return { form: { email: null } }; }, computed: { ...mapGetters('auth', ['getSeller']) }, methods: { ...mapActions('auth', ['setSeller']) }, created() { this.form.email = this.getSeller.email; } -- vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in callback for watcher

vuex do not mutate vuex store state outside mutation handlers

拜拜、爱过 提交于 2020-02-08 10:57:05
问题 [vuex] do not mutate vuex store state outside mutation handlers. When trying to edit the fields this message is shown in the terminal. How do I use the form correctly? <q-editor v-model="form.email" min-height="5rem" /> - data() { return { form: { email: null } }; }, computed: { ...mapGetters('auth', ['getSeller']) }, methods: { ...mapActions('auth', ['setSeller']) }, created() { this.form.email = this.getSeller.email; } -- vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in callback for watcher

Vuex action which returns a promise never resolves or rejects

浪子不回头ぞ 提交于 2020-02-06 04:43:37
问题 I'm trying to build up my API service in my VueJS application by using Vuex. I'm in the process of refactoring some stuff to centralize error handling, clean-up, etc. The issue I'm running into is properly chaining Promises through my function calls. At the root level, I have a BaseService class, which simply make API requests using AXIOS (not full class): export abstract class BaseService { protected readonly API: AxiosInstance; // Full init left out protected deleteItem(url: string):

Vuex Mapping Getter with Argument - Cached?

你说的曾经没有我的故事 提交于 2020-02-03 08:59:45
问题 Here is an example of a Vuex Store with a parameterized getter which I need to map onto the Vue instance to use within the template. const store = new Vuex.Store({ state: { lower: 5, higher: 10, unrelated: 3 }, getters: { inRange: state => value => { console.log('inRange run') return (state.lower <= value) && (state.higher >= value) } }, mutations: { reduceLower: state => state.lower--, incrementUnrelated: state => state.unrelated++ } }) new Vue({ el: '#app', template: "<div>{{ inRange(4) }},

理解Vuex

天涯浪子 提交于 2020-02-01 20:09:55
Vuex 一句话概括:state是数据源,mutation/action触发修改数据(getter封装数据),将state映射到view。 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。 每个应用将仅仅包含一个 store 实例 如果有些状态严格属于单个组件,最好还是作为组件的局部状态。你应该根据你的应用开发需要进行权衡和确定。 ----摘自官网 1.State 总结:存储状态管理数据 2.Getter 有时候我们需要从 store 中的 state 中派生出一些状态,例如对列表进行过滤并计数。 Vuex 允许我们在 store 中定义『getters』(可以认为是 store 的计算属性)。 组件获取 state 用 vuex 的 getter。 Getters 会暴露为 store.getters 对象。 ----摘自官网 总结:getter用于获取state数据(获取的数据可能经过封装,getters只是用来读取数据,不能用来改变数据。) 3.Mutation 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。 不能直接调用一个 mutation handler。这个选项更像是事件注册:“当触发一个类型为 increment 的 mutation 时,调用此函数。” 可以向 store.commit 传入额外的参数,即

How to get collection from firestore and set to vuex state when the app is rendered?

天大地大妈咪最大 提交于 2020-02-01 04:29:05
问题 I have a firestore collection called categories. The documents in this collection are used by every page (route) in my vue application so I figured that the most efficient way to access this data would be to have a categories state in my store.js such that each component can access the categories state when it needs to instead of getting it from firestore each time. How would I set the contents of the categories collection to my vuex state when the application is rendered? Here is my store.js

How to get collection from firestore and set to vuex state when the app is rendered?

陌路散爱 提交于 2020-02-01 04:29:04
问题 I have a firestore collection called categories. The documents in this collection are used by every page (route) in my vue application so I figured that the most efficient way to access this data would be to have a categories state in my store.js such that each component can access the categories state when it needs to instead of getting it from firestore each time. How would I set the contents of the categories collection to my vuex state when the application is rendered? Here is my store.js

Vuex-devtools插件的作用及用法

心不动则不痛 提交于 2020-01-31 16:30:31
detools插件作用:跟踪记录每一次改变state的状态,从而知道是哪个组件修改了state (前提:state是通过 mutations 修改) 如下例,目标为通过点击按钮修改mutations中的counter vuex配置文件index.js 创建store文件夹,在其中创建index.js文件来存放Vuex配置代码 import Vue from 'vue' import Vuex from 'vuex' //1、安装插件 Vue . use ( Vuex ) //2、创建对象 const store = new Vuex . Store ( { state : { counter : 0 } , //state中存放数据 mutations : { increament ( state ) { state . counter ++ } //mutations中确定方法 } } ) //导出store export default store 挂载到Vue实例中 为了让所有的Vue组件都可以使用这个store对象: 在main.js中导入store对象,并且放在new Vue中,这样,在其他Vue组件中,就可以通过this.$store的方式,获取到这个store对象 main.js文件: import Vue from 'vue' import App from '.

I want to use window.localStorage in Vuex in Nuxt.js

主宰稳场 提交于 2020-01-29 03:16:49
问题 I developing nuxt.js app. And point is login & logout. We will develop a login to the JWT system. You must remain logged in at vuex. However, when I refresh the page, vuex is initialized. I've read git vuex-persistedstate , but it's hard to understand just how to initialize and set it. What is the best way to develop a login system in nuxt.js? Thanks. 回答1: Using vuex-persisted state would be the best use case for your scenario. I will walk you through the process of using vuex-persisted state