vuex

VueJS + VUEX + Firebase: Where To Hook Up Firebase?

≡放荡痞女 提交于 2019-11-30 12:09:16
问题 I would like to integrate Firebase in my Vue.JS app. I wonder WHERE to put the references to Firebase. 回答1: To install firebase as a dependency in your project cd into your project directory and run the following command in the command line npm install --save firebase Now in your main.js file add this import Vue from 'vue' import App from './App.vue' import * as firebase from 'firebase' import { store } from './store/store' const config = { apiKey: "xxxxxxx", authDomain: "xxxxxxx",

vuex状态管理

删除回忆录丶 提交于 2019-11-30 11:12:09
vuex状态管理 在vue中我们可以使用vuex来保存我们需要管理的状态值,值一旦被修改,所有引用该值的地方就会自动更新。 1.)新建一个vue项目 vue init webpack web //(使用webpack创建一个项目名为web的项目) 2.)安装vuex npm install vuex --save 3.)启动项目 npm run dev    4.)在src目录下新建一个目录store,在该目录下新建一个index.js的文件,用来创建vuex实例,然后在该文件中引入vue 和 vuex,创建vuex.store实例保存到变量store中,最后export default导出store {* const store = new Vuex.Store({}) export default store; *} 5.)在main.js文件中引入该文件 在文件里面添加 import store from “./store” {* new Vue({ el:"#app", store, router, ... }) *} 6.)state: vuex中的数据源,我们需要保存的数据就保存在这里,可以在页面通过this.$store.state来获取我们定义的数据 {* index.js const store = new Vuex.store({ state :{ count

活用控制反转 -- 解决一个棘手信息传递问题

扶醉桌前 提交于 2019-11-30 08:02:23
在我初学编程的时候,还没写过完整点的项目就看过了一些高阶概念。在没有实践时,这些概念的神奇和强大之处很难被完全体会的。而一旦自己在摸索中应用了,瞬间觉得打开了一扇大门,技能又提升了一个层次。控制反转(Inversion of Control)就是这些强大概念之一。一年前在 MPJ 老师的 频道 上了解到了,但一直没自己独立创造场景用过。直到最近在项目中遇到个坑才用起来。 其实控制反转或者依赖注入(这两个感觉是同一个东西,看你从什么角度看)在前端框架中已经大量使用了。最早由 Angular 普及,后续的现代框架都有应用。比如 React 开发中目前最火的组件设计模式 Render Props,就是控制反转的一种应用。离开框架,在日常开发中,应用这种技巧可以帮助我们解决很多棘手的问题,今天就讲下我在开发中的一次应用。 项目场景是这样的:技术栈是 Nuxt + Vuex。项目需要连接 Web Socket,然后根据 Socket 传来的数据,对 Vuex 里面相应的数据进行修改。公司为了节约成本,将 Socket 数据压缩了,而且不是全量推送,这要求前端收到数据后对数据进行解压,然后对数据进行遍历查找,更新,重新计算和排序,总之对 Socket 数据的处理非常复杂。为了不影响性能,我把 Socket 连接和数据处理放进了 Web Worker。先来看下项目结构。 下面是我封装的一个

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

瘦欲@ 提交于 2019-11-30 07:45:16
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. 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. Open command line, cd to your project directory, then enter npm install --save vuex-persistedstate . This

Vuex & Websockets

折月煮酒 提交于 2019-11-30 07:06:29
So currently I am working with VueJS 2 and I am very new with it. Now I was getting some help with some other people, but I am still stuck. Here is what I want to achieve (example - closely linked to what I want): I have a NodeJS application that listens on WebSockets. The application listens for connections via WebSocket and will take JSON data, with a command and then a data object with any content needed for that command. The command for example could be login, and the data be username and password. The login function on the NodeJS application will then take this data, do what it needs and

Visual Studio Code breakpoint appearing in wrong place

被刻印的时光 ゝ 提交于 2019-11-30 05:56:52
问题 In my Vue+Vuex project, I am trying to debug using Visual Studio Code. I have the debugger launching properly using Chrome debug tools, and properly using a map, but when I try to place breakpoints in my .js or .vue files, VS Code seems to be placing the breakpoints in the wrong place. For example, here I try to place a breakpoint in one of my getters on line 40, but it ends up 15 lines later: Is this a bug in VS Code, or perhaps some other issue? Any suggestions on how to fix? Other

VueJS + VUEX + Firebase: Where To Hook Up Firebase?

和自甴很熟 提交于 2019-11-30 02:10:12
I would like to integrate Firebase in my Vue.JS app. I wonder WHERE to put the references to Firebase. To install firebase as a dependency in your project cd into your project directory and run the following command in the command line npm install --save firebase Now in your main.js file add this import Vue from 'vue' import App from './App.vue' import * as firebase from 'firebase' import { store } from './store/store' const config = { apiKey: "xxxxxxx", authDomain: "xxxxxxx", databaseURL: "xxxxxxx", storageBucket: "xxxxxxxx", messagingSenderId: "xxxxxxx" }; firebase.initializeApp(config); Vue

vuex 源码分析(六) 辅助函数 详解

无人久伴 提交于 2019-11-29 23:37:22
对于state、getter、mutation、action来说,如果每次使用的时候都用this.$store.state、this.$store.getter等引用,会比较麻烦,代码也重复和冗余,我们可以用辅助函数来帮助我们生成要的代码,辅助函数有如下四个: mapState(namespace, map)        ;用于获取state mapGetters(namespace, map)       ;用于获取getters mapMutations(namespace, map)      ;用于获取mutations mapActions(namespace, map)      ;用于获取actions 每个辅助函数都可以带两个参数:   namespace    ;命名空间,也就是模块名   map       ;要获取的信息 map有两种用法,可以是对象(键名是当前Vue实例设置的变量名,值是从store要获取的变量名)或者字符串数组(此时获取和设置的变量名为同一个)。 注:使用辅助函数需要在根节点注入store ps:很多新手可能只会使用辅助函数,不知道还可以用this.$store.state,this.$store.getter这些用法... 这些辅助函数返回的都是一个对象,我们可以 配合ES6的对象展开运算符,我们可以极大地简化写法 ,例如: <

How to clear state in vuex store?

会有一股神秘感。 提交于 2019-11-29 23:22:25
My state in vuex store is huge. Is there a way to reset all the data in state in one go, instead of manually setting everything to null? Michael Horojanski I have just found the great solution that works for me. const getDefaultState = () => { return { items: [], status: 'empty' } } // initial state const state = getDefaultState() const actions = { resetCartState ({ commit }) { commit('resetState') }, addItem ({ state, commit }, item) { /* ... */ } } const mutations = { resetState (state) { // Merge rather than replace so we don't lose observers // https://github.com/vuejs/vuex/issues/1118

How do I format currencies in a Vue component?

喜欢而已 提交于 2019-11-29 22:05:10
My Vue component is like this : <template> <div> <div class="panel-group"v-for="item in list"> <div class="col-md-8"> <small> Total: <b>{{ item.total }}</b> </small> </div> </div> </div> </template> <script> export default { ... computed: { list: function() { return this.$store.state.transaction.list }, ... } } </script> The result of {{ item.total }} is 26000000 But I want format it to be like this : 26.000.000,00 In jquery or javascript, I can do it But, How to do it in vue component? UPDATE: I suggest using solution with filters, provided by @Jess. I would write method for that, and then