vuex

How can I solve “Uncaught TypeError: Cannot read property 'get' of undefined” in the vuex store?

非 Y 不嫁゛ 提交于 2019-11-27 08:25:01
问题 If I try this .$session.get(SessionKeys.Cart) in my component like this : <template> ... </template> <script> ... export default { ... methods: { add(item) { console.log(this.$session.get(SessionKeys.Cart) ... } } } </script> It works. I success get session cart But if I try it in the my vuex store like this : import { set } from 'vue' // initial state const state = { list: {} } // getters const getters = { list: state => state.list } // actions const actions = { addToCart ({ dispatch,commit

Debounce computed properties/getters in Vue

这一生的挚爱 提交于 2019-11-27 06:54:13
问题 I can't seem to debounce (lodash) computed properties or vuex getters. The debounced functions always return undefined. https://jsfiddle.net/guanzo/yqk0jp1j/2/ HTML: <div id="app"> <input v-model="text"> <div>computed: {{ textComputed }} </div> <div>debounced: {{ textDebounced }} </div> </div> JS: new Vue({ el:'#app', data:{ text:'' }, computed:{ textDebounced: _.debounce(function(){ return this.text },500), textComputed(){ return this.text } } }) 回答1: As I mention in my comment, debouncing

Vuex state on page refresh

懵懂的女人 提交于 2019-11-27 06:20:34
My app uses the Firebase API for User Authentication, saving the Login status as a boolean value in a Vuex State. When the user logs in I set the login status and conditionally display the Login/Logout button accordingly. But when the​ page is refreshed, the state of the vue app is lost and reset to default This causes a problem as even when the user is logged in and the page is refreshed the login status is set back to false and the login button is displayed instead of logout button even though the user stays logged in.... What shall I do to prevent this behavior Shall i use cookies Or any

分享一个vue项目“脚手架”项目的实现步骤

倖福魔咒の 提交于 2019-11-27 05:56:17
搭建缘由 源于公司每次新启动一个由多人协同开发的项目都由负责人初始化项目之后,每个人再去从私服pull一下项目才开始开发。但是每次初始化工程都是一步步的造轮子,一个个依赖去安装,新建一个个不同功能的文件夹,而每个负责人所初始化的项目目录、以及模块引入方式参差不齐,以至于开发中后期因每个人开发风格的不同导致git提交时总会产生各种各样的“冲突”,也会产生后期代码维护成本增加,所以就有必要考虑一下做一个统一的类似“脚手架”的功能了,用来给团队开发带来便捷的、统一的、易扩展的项目基础。 预实现的功能 公共样式统一管理,全局sass的友好引入 公共js统一管理 解决vue脚手架初始化的部分问题 路由形式、接口统一管理 store模块化管理 定义vue前端项目必用的方法 修改好统一的config配置 全局混入/指令的封装 必要的依赖项 node-sass sass sass-resources sass-loader sass-recources-loader vuex vuex-persistedstate axios babel-polyfill 项目目录如下 配置公共sass 目录assets>scss文件形式 mixin.scss内容详见 mixin公共sass函数 common.scss内容如下 @import './mixin.scss'; // 公共函数 @import '.

Accessing Vuex state when defining Vue-Router routes

删除回忆录丶 提交于 2019-11-27 05:33:04
问题 I have the following Vuex store (main.js): import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //init store const store = new Vuex.Store({ state: { globalError: '', user: { authenticated: false } }, mutations: { setGlobalError (state, error) { state.globalError = error } } }) //init app const app = new Vue({ router: Router, store, template: '<app></app>', components: { App } }).$mount('#app') I also have the following routes defined for Vue-Router (routes.js): import Vue from 'vue'

【实习周报】2019年4月 前端开发实习工作周报汇总

梦想的初衷 提交于 2019-11-27 05:04:13
以下记录的是今年4月笔者在公司进行web前端工作的每周工作总结,其中隐去了项目的具体名称、人名、公司名等。 2019.4.1-2019.4.3 本周工作内容: 本周主要完成了训练场(Training)页面的静态显示;实现了其拖拽用户元素的效果 不足之处:本周笔者在工作上的不足之处主要是css布局和vuex方面上 首先是css的布局问题,虽然笔者在编写页面时发现了使用纯比例宽度布局外层div时在页面进行缩放和放大是效果都不佳,但是却没有解决这个问题,之后成哥提出来才明白问题的严重性,但是在css布局方面我仍然有疑问,比如使用百分比的大小是参考了之前bootstrap的栅格化的一些思想,bootstrap的栅格化在源码实现方面也使用到了百分比大小,不过忽略了它其实还有媒体查询以及这个指定视口的问题…还是有很多疑问需要解决 再一个就是vuex的不熟悉了,笔者在本周接触到了使用vuex在兄弟组件之间进行通信的问题,但是使用的不够熟练而且风格和之前的代码有差别==| 下一阶段的工作:研究css布局的技巧,学会如何进行响应式布局,加强对flex布局的理解和学习 加强对vuex的学习,在下一阶段将自己写的veux数据传递风格和之前的代码风格保持一致(如图)   2019.4.8-2019.4.12 本周工作内容:本周笔者基本了解了vuedraggable库的一些常用API

vuejs 2 how to watch store values from vuex

无人久伴 提交于 2019-11-27 05:02:27
问题 I am using vuex and vuejs 2 together. I am new to vuex , I want to watch a store variable change. I want to add the watch function in my vue component This is what I have so far: import Vue from 'vue'; import { MY_STATE, } from './../../mutation-types'; export default { [MY_STATE](state, token) { state.my_state = token; }, }; I want to know if there are any changes in the my_state How do I watch store.my_state in my vuejs component? 回答1: Let's say, for example, that you have a basket of

vue中的状态管理 vuex store

旧时模样 提交于 2019-11-27 04:53:16
vuex store 是 响应式 的,当vue组件从store中读取状态(state)时,若store中的状态发生更新时,会及时的响应给其他的组件。 store 中的四个核心选项: state mutation getters actions 1)state是用来存放组件之间共享的数据,一般会在组件的 计算属性 中获取state的数据。 使用:this.$store.state. ... 2) 在 Vuex store 中,实际改变 状态(state) 的唯一方式是通过提交(commit) 一个 mutation 。 在组件里提交: this.$store.commit('change', payload ) mutations下的函数接收state作为参数,接收一个叫做payload(载荷)的东西作为第二个参数,这个东东是用来记录开发者使用该函数的一些信息,比如说提交了什么,提交的东西是用来干什么的,包含多个字段,所以载荷一般是对象 还有一点需要注意: mutations方法必须是同步方法 !   var myStore = new Vuex.Store({ state:{ //存放组件之间共享的数据 name:"jjk", age:18, num:1 }, mutations:{ //显式的更改state里的数据 change(state,a){ state.num += a;

vuex - is it possible to directly change state, even if not recommended?

若如初见. 提交于 2019-11-27 03:27:57
问题 The documentation at https://vuex.vuejs.org/en/getting-started.html says, You cannot directly mutate the store's state. The only way to change a store's state is by explicitly committing mutations. My question is, is that good practice, or that's how the internals of the Vuex state work? In other words, is the Vuex state reactive in the same way Vue data is (it converts the js object to an observable), or is it something else? A similar question - could you directly change the state in an

vue梳理(2)

孤街浪徒 提交于 2019-11-26 23:43:57
-app.vue作为根组件被挂载到index.html文件里,其他的所有组件都是在app.vue组件里做文章。 展示给用户的就是app.vue里的内容,你觉得删的没有内容了但实际还有很多是因为什么呢?因为router-view标签,他显示的是当前路由地址对应的内容(组件),也就是说当前路由对应哪个组件哪个组件显示在router-view这里,被用户看到 如果你给我的是2倍图,那我跟元素字体大小设置为50px,则2倍图上量取的px直接除以100即可。如果你给我1倍图那我设置根元素字体大小100px,如果你给我4倍图那我设置根元素字体大小25px。好处就是量取的px值直接除以100即可转化为rem单位 使用less定义变量 创建一个less文件里面定义一个颜色变量$bgColoer="red" 使用时在某个组件style标签里通过@import ""引入即可使用该变量了 轮播图安装指定版本 npm install vue-awesome-swiper@2.6.7 --save 参数与swiper3一样 swiper代表几个轮播图,循环这个标签会多出几个轮播图 在swiper-slide上面v-for循环,一个swiper-slide标签代表一个轮播图里的一个面一个图片,有几个swiper-slide就有几个img轮播 一个图片也可以是多个icons,就循环吗 轮播图直接这样写