vuex

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

扶醉桌前 提交于 2020-01-29 03:16:38
问题 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

Vuex的学习(18)

落爺英雄遲暮 提交于 2020-01-27 20:39:37
使用Vuex优化前面的Todos 基本要点与基本流程 //TodoHeader this . $store . dispatch ( 'addTodo' , todo ) //actions addTodo ( { commit } , todo ) { // 提交一个comutation请求 commit ( ADD_TODO , { todo } ) // 传递给mutation的是一个包含数据的对象 } , //mutations [ ADD_TODO ] ( state , { todo } ) { // 方法名不是ADD_TODO, 而是add_todo state . todos . unshift ( todo ) } , 一旦要读vuex管理的状态或者计算属性都用computed 一般的串变成变量用中括号:[ADD_TODO] 强调多组件状态管理,一个组件用的就不用vuex了 对于get set 就要单独写,注意在getters中不要用this,传一个getters去获取当前模块的方法 < input type = "checkbox" v - model = "checkAll" / > checkAll : { get ( ) { // 决定是否勾选 return this . $store . getters . isAllSelect } , set (

How to use Moment.js with Vuexfire

拈花ヽ惹草 提交于 2020-01-27 08:47:24
问题 I am building a Vue.js application that uses Vuexfire in a store.js file. My application enables a user to push user-inputted posts with timestamps into Firestore. I am configuring my Vuexfire action handler to commit to mutation the firebase payload arranged in order by timestamp, like so: import Vue from "vue"; import Vuex from "vuex"; import firebase from "firebase"; import { vuexfireMutations, firestoreAction } from 'vuexfire' import { db } from "@/main"; import moment from 'moment' Vue

uni-app 全局websocket 链接 简易

笑着哭i 提交于 2020-01-26 11:11:40
websocketStore.js import Vue from 'vue' import Vuex from 'vuex' Vue . use ( Vuex ) export default new Vuex . Store ( { state : { socketTask : null , eventlist : [ ] } , mutations : { WEBSOCKET_INIT ( state , url ) { // 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】 state . socketTask = uni . connectSocket ( { url : "xxxxxxx" , // 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】 success ( data ) { console . log ( "websocket连接成功" ) ; } , } ) ; // 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】 state . socketTask . onOpen ( ( res ) => { console . log ( "WebSocket连接正常打开中...!" ) ; state . is_open

vuex持久化+模块化实战用法(进阶篇)

﹥>﹥吖頭↗ 提交于 2020-01-25 10:38:09
上一篇: vuex刷新数据消失不见解决方案 Vuex模块化 模块化后的 store 大概长这样, 如果画的不对,欢迎留言 这样经过模块化的vuex,每个模块维护着不同组件的数据,清晰直观 编码实现 创建store文件夹, 创建index.js 作为vuex的入口js import Vue from "vue" ; import Vuex from "vuex" ; import createPersistedState from "vuex-persistedstate" ; import login from "./modules/login" ; import loginOther from "./modules/loginOther" ; Vue . use ( Vuex ) ; export default new Vuex . Store ( { plugins : [ createPersistedState ( { storage : window . sessionStorage , reducer ( val ) { return { // 需要储存的数据 login : val . login , } } } ) ] , modules : { login , loginOther , //带有Other的是不需要刷新保存数据的,不带的是需要刷新保存的 } ,

VueJS: Cannot read property 'dispatch' of undefined

送分小仙女□ 提交于 2020-01-24 21:07:47
问题 I start my simple project with VueJS and Vuex. And I have a problem witch calling method from store. When I click my button in console I see this error Uncaught TypeError: Cannot read property 'dispatch' of undefined at VueComponent.onSignin Here is my component with button which should call dispatch Login component. And here is my store index.js Vuex.Store And here you can find full repo I read many topics on another forum but I stil don't know why it is not work, because I do similar

Adding Mutations to Vuex store as part of Vue Plugin

故事扮演 提交于 2020-01-24 04:19:31
问题 I'm creating a small Vue Plugin that allows a user to add a "page notification" from within any component. I've successfully implemented something like: this.$notifications.add("a message"); And it works! But I've had to register the mutations and actions required for my plugin to work as part of the file that sets up the rest of the store for my app: export default new Vuex.Store({...}) Is there a way to add actions and mutations to my store from within my plugin? It currently looks like

Adding Mutations to Vuex store as part of Vue Plugin

雨燕双飞 提交于 2020-01-24 04:19:04
问题 I'm creating a small Vue Plugin that allows a user to add a "page notification" from within any component. I've successfully implemented something like: this.$notifications.add("a message"); And it works! But I've had to register the mutations and actions required for my plugin to work as part of the file that sets up the rest of the store for my app: export default new Vuex.Store({...}) Is there a way to add actions and mutations to my store from within my plugin? It currently looks like

When to use the base Vue instance, Vuex or mixin?

假装没事ソ 提交于 2020-01-23 10:03:31
问题 In Vue, you can store commonly used variables and methods in the base Vue instance. This way other components can access this data. new Vue({ data: { name: 'John' } }); If you are using Vuex for state management you could also store this data here as well. const store = new Vuex.Store({ state: { name: 'John' } } From my understanding, Vue mixins also offer the same functionality (allowing any component to access this commonly shared data globally). Vue.mixin({ data() { return { name: 'John' }

duplicate namespace auth/ for the namespaced module auth

一笑奈何 提交于 2020-01-23 04:09:37
问题 I've been getting this error after installing nuxtjs module. I have tried every trick in the book to fix it, but seems like nothing is working.Added more information. [vuex] duplicate namespace auth/ for the namespaced module auth I've been frustrated with it. auth: { plugins: [{ src: '~/plugins/axios', ssr: true }, '~/plugins/auth.js'], vuex: { namespace: 'auth' }, strategies: { local: { endpoints: { login: { url: "login", method: "post", propertyName: "meta.token" }, user: { url: "me",