vuex

Getting router params into Vuex actions

谁都会走 提交于 2019-12-03 14:10:39
I would like to pass router params into Vuex actions, without having to fetch them for every single action in a large form like so: edit_sport_type({ rootState, state, commit }, event) { const sportName = rootState.route.params.sportName <------- const payload = {sportName, event} <------- commit(types.EDIT_SPORT_TYPE, payload) }, Or like so, edit_sport_type({ state, commit, getters }, event) { const payload = {sportName, getters.getSportName} <------- commit(types.EDIT_SPORT_TYPE, payload) }, Or even worse: grabbing params from component props and passing them to dispatch, for every dispatch.

Vuex getters in computed properties showing undefined until full page load

爷,独闯天下 提交于 2019-12-03 12:23:16
I'm trying to create computed properties using data pulled with the mapGetters function in vuex, but I'm always getting undefined, until the page/dom fully loads. Here's an example for an isRegistered computed property that I use to hide/display certain buttons. computed: { ...mapGetters(['solos', 'user']), isRegistered () { return this.solos.registered.indexOf(this.user._id) !== -1 } } Here is the HTML for buttons that use the isRegistered computed property. <a href="#" class="register-button" v-if="!isRegistered">REGISTER NOW</a> <a href="#" class="registered-button" v-if="isRegistered"

vue & vuex getter vs passing state via props

╄→гoц情女王★ 提交于 2019-12-03 10:40:42
I have seen many people advising to pass state to components via props rather than accessing the vue state directly inside the component in order to make it more reusable. However, if I do this consistently this would mean that only the routes root component would communicate with the store and all data needs to be passed through the nested hierarchy in order to get the final component. This seems like it would easily cause a mess: Dashboard Profile Billing History CreditCards CreditCard How would I load data for a users creditcard? In Dashboard and pass it all the way down the tree? It will

vue中小型项目开发浅谈

限于喜欢 提交于 2019-12-03 10:22:46
组件的本质   组件的本质就是一个可以交互的视图模板 controller去哪了   在react中存在展示组件与容器组件,其中展示组件展示单纯的展示,而容器组件里面则是react与redux沟通的桥梁,而redux是包含业务逻辑的地方,所以controller存在于react的容器组件中,但是在vue中没有容器组件的概念,然而我们可以编写出一个容器组件,用于存在其他展示组件,这通常是一个页面或者是页面里的某个模块 是否需要model层   对于中小型项目,大部分业务逻辑都已经被node中间层给处理了,前端只是单纯的拿到数据 展示数据,并不存在复杂的业务逻辑,但也不是完全没有业务逻辑,单纯开辟一个model层太过于浪费,是否可以将model层放于容器组件之中? 真的需要vuex吗   vuex是为了解决组件间数据共享,组件数据深层传递问题,但是并不是只有vuex才可能解决这个问题,组件间数据共享可以用sessionStorage,深层传递可以用provide/inject mvc在前端   mvc的本质是大型项目的解耦,其解决办法是业务逻辑于视图的分离,然而什么是视图层,什么是业务逻辑层,并不是说 放在pages里面就是视图层,放在model里面就是数据层,本质在于你如何分离你的代码,在上面 我将业务逻辑放在容器层里面,而将视图层 分散在组件里面

Vue.js: Nuxt error handling

时光毁灭记忆、已成空白 提交于 2019-12-03 10:05:55
Struggling a bit to set up error handling with vuex. There seems to be quite a few ways to do so and little documentation on proper error handling. I've been experimenting with four alternatives, though I haven't found a satisfying solution yet. Alternative 1 - Catching and processing errors on component in pages/login.vue: export default { methods: { onLogin() { this.$store.dispatch('auth/login', { email: this.email, password: this.password, }).then(() => { this.$router.push('/home'); }).catch((error) { // handle error in component }); }, }, } in store/auth.js: export const actions = { login(

How to check in a Vue component if a user is authenticated in Laravel?

笑着哭i 提交于 2019-12-03 09:57:15
问题 As the title states, I'm a little confused how I would tackle a method in my Vue Component with if/else statement based on if the user is logged in and authenticated with Laravel's Auth facade. I'm making various Axios requests which I need to allow/disallow based on if user logged in. I have VUEX setup and was thinking that I can use local storage somehow to have a state for isLoggedin for example that works with Laravel. But I don't know if this is correct method, or secure and presumably

Vuex 理解 与 知识的详解

自作多情 提交于 2019-12-03 09:57:12
一 关于存储跟数据动态传输的问题。我这边提到了vuex 仓库 管理 体系。首先我来说一下关于vuex的理解。 先说一下关于 vuex 到底是什么? 官方的解释意思是 程序开发的状态管理模式 这个状态我们可以累计额在data的属性里面。 需要共享其他组件使用的部分。 也就是说 ,我们的需要共享data,使用vuex 进行统一中式管理 二 vuex 中的默认五种基本对象 state 存储状态。 getters 对象数据获取之前的再次编辑,可以理解为state计算属性。我们的组件中使用$sotre.gerers.fun() mutations 修改状态,并同步,在组件中使用$store.commit('params') 这个和我们组件中自定义类型保持一致性 actions 异步操作。在组件中使用$store.dispath('') 可以分布式进行 modules:store的子模块,为了开发大型项目,方便状态管理而使用的。这里我们就不解释了,用起来和上面的一样。 三 下面对案例做一定的归纳 1 首先先更新vuex 依赖包 cnpm run vuex --save 2 创建后执行响应的代码。 cd app/ npm run dev 3 接下来我们在src目录下创建一个vuex文件夹 并在vuex文件夹下创建一个store.js文件 文件夹目录长得是这个样子 4、目前我们还没有引入vuex

webpack 引入 CDN 加速

末鹿安然 提交于 2019-12-03 08:48:39
webpack 引入 cdn 加速,用比较流行的 vue + webpack 来说明好了 1、在SPA模版入口页面,项目根目录下的 index.html 中引入 CDN <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>vue + webpack + cdn</title> </head> <body> <div id="app"></div> <script src="https://cdn.bootcss.com/vue/2.5.2/vue.min.js"></script> <script src="https://cdn.bootcss.com/vue-router/3.0.1/vue-router.min.js"></script> <script src="https://cdn.bootcss.com/vuex/3.0.1/vuex.min.js"></script> </body> </html> 2、在配置文件 build/webpack.base.conf.js 中添加 module.exports = { ... externals: { 'vue':

服务器端渲染与Nuxt.js

那年仲夏 提交于 2019-12-03 07:55:08
本文转载于: 猿2048 网站➪ https://www.mk2048.com/blog/blog.php?id=hca02aakaa 从前端发展史来看服务器端渲染 前段时间在知乎上看到一篇提问,说的是为什么现在又开始流行服务器端渲染html了。整理了网上一些评论,结合自己的想法,整理出了一段前端发展史。 早在1989年,HTML的诞生是一个物理学家为了方便学术文档的分享而创造,这个也是前端起始的时间。后来,CSS和Javascript加入前端行列,用来渲染页面样式和处理页面动效逻辑,前端三剑客成立。刚开始的前端程序员,其实就是做切图写样式(CSS)和做页面特效(JS)等一切基础的工作,处于程序员鄙视链的底层。 随着互联网发展与技术进步,静态页面已经远不能满足产品需求,页面上要根据逻辑产生动态的数据,这时,便迎来PHP,JSP等为代表的web1.0时代。此时的服务器渲染,是以“文档”为核心思想。服务器端的逻辑是把HTML,CSS和JS当做一个静态文件,对“文档”而言不存在“指令”和“数据”的区别,一切都是数据。所以我们可以看到服务器渲染,GET就是请求一个文件,而web 1.0时代的诸多服务端框架最基础的组件之一就是文档模版,比如asp, JSP之类,核心设计理念就是HTML文件里放占位符然后由服务端逻辑替换成实际数据后一股脑返回。很多中小型项目,不分前端后端

震惊!喝个茶的时间就学会了vuex

戏子无情 提交于 2019-12-03 07:04:46
本文转载于: 猿2048 网站▶ https://www.mk2048.com/blog/blog.php?id=h2i2aj20jb 写在前面 我很欣赏震惊部,因为他们的标题每次写的都很好0.0 什么是vuex 先给出 官网地址 官方解释: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化 大白话:对数据(data)统一的管理,如果涉及到了数据的处理,来,到vuex里面进出吧!就像是超市对商品的统一管理一样 为了使用vuex而做的准备 安装vuex npm install --save vuex <!--这里假定你已经搭好vue的开发环境了--> 配置vuex 1、首先创建一个js文件,假定这里取名为store.js 2、在main.js文件中引入上面创建的store.js //main.js内部对store.js的配置 import store from '"@/store/store.js' //具体地址具体路径 new Vue({ el: '#app', store, //将store暴露出来 template: '<App></App>', components: { App } }); store.js中的配置 import Vue from 'vue'; /