vuex

How can I close modal after click save button in vue component?

て烟熏妆下的殇ゞ 提交于 2019-12-01 23:38:45
My vue component like this : <template> <div ref="modal" class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form> ... <div class="modal-footer"> ... <button type="button" class="btn btn-success" @click="addPhoto"> Save </button> </div> </form> </div> </div> </div> </template> <script> export default { ... methods: { addPhoto() { const data = { id_product: this.idProduct }; this.$store.dispatch('addImageProduct', data) .then((response) => { this.$parent.$options.methods.createImage(response) }); }, } } </script> If I click button

vuex commit does not commit to store

五迷三道 提交于 2019-12-01 23:21:46
问题 I'm having trouble getting my commit to work on a store. I am calling the mutation via an action, which seems to work fine. export const location = { state: { x: 0, y: 0, z: 0, extent: [], epsg: 'EPSG:3857' }, mutations: { setLocation(state, payload) { // mutate state console.log("Commit"); state.x = payload.x; state.y = payload.y; console.dir(state); //this does return the mutated state. } }, actions: { setLocation(context, payload) { console.dir(payload); context.commit('setLocation',

vuex commit does not commit to store

ぃ、小莉子 提交于 2019-12-01 22:12:08
I'm having trouble getting my commit to work on a store. I am calling the mutation via an action, which seems to work fine. export const location = { state: { x: 0, y: 0, z: 0, extent: [], epsg: 'EPSG:3857' }, mutations: { setLocation(state, payload) { // mutate state console.log("Commit"); state.x = payload.x; state.y = payload.y; console.dir(state); //this does return the mutated state. } }, actions: { setLocation(context, payload) { console.dir(payload); context.commit('setLocation', payload); } }, getters: { mapLocation(state) { return state } } } The action is imported into my component:

vuex状态管理

房东的猫 提交于 2019-12-01 22:06:15
vuex是什么 vuex 是一个专门为vue.js应用程序开发的状态管理模式。 vuex中,有默认的五种基本的对象: state :存储状态(变量) getters :对数据获取之前的再次编译,可以理解为state的计算属性。我们在组件中使用 $sotre.getters.fun() mutations :修改状态,并且是同步的。在组件中使用$store.commit('',params)。这个和我们组件中的自定义事件类似。 actions :异步操作。在组件中使用是$store.dispath('') modules :store的子模块,为了开发大型项目,方便状态管理而使用的。这里我们就不解释了,用起来和上面的一样。 1 .安装vuex npm install vuex --save 2 . 新建 store/ store.js 文件,引入 vuex import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const state = { count: 1 } const mutations = { increment (state) { state.count++ } } export default new Vuex.Store({ state, mutations }) 3.在main.js中引入store

vuex的学习

醉酒当歌 提交于 2019-12-01 18:43:45
vuex是什么? vuex是专为vue.js应用程序开发的状态管理模式 它采用集中式存储管理应用所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化 vuex也集成到vue的官方调式工具devtools extension 状态管理到底是什么? 说简单点就是把需要多个组件共享的变量全部存储到一个对象里面,然后将这个对象放到顶层的实例中,让其他组件可以使用 为什么我们不自己封装一个对象来管理呢? 因为封装在vuex里面的数据能够直接做到响应式 什么时候用vuex 当多个视图都依赖同一个状态的时候 vuex基本使用 在src目录下创建文件夹store,并且创建一个index.js文件, import Vue from 'vue' import Vuex from 'vuex' // 1.安装插件 Vue.use(Vuex) //创建实例 const store = new Vuex.Store({ state:{ count:0 }, mutations:{ increment(state){ state.count++ } } }) 然后让所有Vue组件都能使用这个store对象 来到main.js文件,导入store对象,并放到new Vue中 这样,其他组件就可以通过this.$store的方式,获取到这个store对象了 import Vue from 'vue'

Vuejs with axios request in vuex store: can't make more than one request, why?

别来无恙 提交于 2019-12-01 17:47:58
问题 I'm building some vuejs dashboard with vuex and axios, between others, and I've been struggling for a while on a pretty pesky problem: it seems I can't make more than one request! All subsequent calls fail with this error: Fetching error... SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer {the_entire_content_of_the_previous_api_response}' is not a valid HTTP header field value. My store looks like that: import axios from "axios"; const state = { rawData1: null,

Vuejs with axios request in vuex store: can't make more than one request, why?

帅比萌擦擦* 提交于 2019-12-01 17:42:40
I'm building some vuejs dashboard with vuex and axios, between others, and I've been struggling for a while on a pretty pesky problem: it seems I can't make more than one request! All subsequent calls fail with this error: Fetching error... SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer {the_entire_content_of_the_previous_api_response}' is not a valid HTTP header field value. My store looks like that: import axios from "axios"; const state = { rawData1: null, rawData2: null }; const actions = { FETCH_DATA1: ({ commit }) => { if (!state.rawData1) return axios.get

pc vue 项目中的菜单权限控制

大兔子大兔子 提交于 2019-12-01 16:16:27
在pc 管理系统这种类型的产品,通常会涉及到账号权限的控制,不同的账号权限能浏览的功能模块是不同的,对应侧边栏菜单模块的显示也会不同。 场景一、(电商类管理系统) 登录 登录后,依次获取账号 tokenId、店铺列表、默认店铺ID、菜单列表 通过菜单列表生成侧边栏,注意router 文件里面定义了全部的页面路由,所以配置新菜单时候需要提供给后端前端定义的页面路径 menuList 数据存起来,可以存在 vuex、sessionStorage,这个数据可以用于router 里面非白名单页面的拦截比对,如果访问当前账号无权限的页面,可将其跳转 404 页面 在路由卫士里面拦截检查 场景二、(电商类单点登录系统) 单点登录类系统,通常会多个项目公用一套登录系统,项目首页直接就是dashboard 或者 index页面,菜单权限数据会放在项目初始化时候通过登录系统返回的 tokenID(可以存放到cookie) 来请求接口获取,然后存到 sessionStorage ,到这里可能会有个问题,每次刷新页面时候都会重复请求这个接口,是没必要的,可以定义一个登录状态标识符,第一次登录成功后就做一个标识,之后项目页面刷新时候不再进行菜单权限接口请求,退出或者tokenID 过期失效时候,进行重置。 同样在路由卫士这样的地方进行跳转路径检查,白名单放行,无权限地址导到 404。 场景三、(关于

[Vue] vuex-interview

試著忘記壹切 提交于 2019-12-01 15:27:00
1.你有使用过 vuex 的 module 吗?主要是在什么场景下使用? 把状态全部集中在状态树上,非常难以维护。 按模块分成多个 module,状态树延伸多个分支,模块的状态内聚,主枝干放全局共享状态 2.vuex 中 actions 和 mutations 有什么区别? action actions 是用来触发 mutations 的,它无法直接改变 state 一些对 State 的异步操作可放在 Action 中,并通过在 Action 中 commit Mutation 变更状态 Action 可通过 store.dispatch() 方法触发,或者通过 mapActions 辅助函数将 vue 组件的 methods 映射成 store.dispatch() 调用 Mutation mutation mutations 可以直接修改 state,在 vuex 的严格模式下,Mutaion 是 vuex 中改变 State 的唯一途径 Mutation 中只能是同步操作通过 store.commit() 调用 Mutation 尽量通过 Action 或 mapMutation 调用而非直接在组件中通过 this.$store.commit() 提交 3.vuex 使用 actions 时不支持多参数传递怎么办? Object 4.你觉得要是不用 vuex

Unable to return value from Vuejs method and firestore

若如初见. 提交于 2019-12-01 12:53:26
问题 i want to return the value from the firestore OnSnapshot function so that i can retrieve the url of user image. I am using vuejs and firestore. And i have activeUserImg function in created property of vue. activeUserImg: function () { const u = firebase.auth().currentUser; firebase.firestore().collection('Colleges').doc(u.uid).onSnapshot(function(doc) { var img_arr=[]; this.img_arr.push(doc.data()) this.img= doc.data().logo }); return this.img || this.$store.state.AppActiveUser.img; } and