vuex

使用Observable实现Vue全局状态共享

非 Y 不嫁゛ 提交于 2020-02-25 15:42:29
项目不大, 又不想用Vuex, 那么使用Observable来实现状态共享也不失为一个选择。 先来看看官方资料: Vue.observable( object ) 2.6.0 新增 参数 :{Object} object 用法 :让一个对象可响应。Vue 内部会用它来处理 data 函数返回的对象 此API为2.6版本新增, 那么低版本是不兼容, 会报出以下错误: vue__.default.observable is not a funcion 解决方法是将Vue升级到^2.6.0 即可。 写个Demo看看 1.创建store // 文件路径 - /store/store.js import Vue from 'vue' export const store = Vue.observable({ count: 0 }) export const mutations = { setCount (count) { store.count = count } } 2. 使用 <template> <div> <label for="bookNum">数 量</label> <button @click="setCount(count+1)">+</button> <span>{{count}}</span> <button @click="setCount(count-1)">-<

Is allowedDate not usable for async or ajax on the vuetify?

和自甴很熟 提交于 2020-02-25 13:24:31
问题 I want to ask methods: { allowedDates(date) { console.log(date) } }, it will console.log all date on every month selected But if I add script ajax/async like this : methods: { allowedDates(date) { console.log(date) this.getData({appDate: date}); // this is async/call ajax on the vuex store } }, it's async without stopping is allowedDate not usable for async or ajax? docs : https://vuetifyjs.com/en/components/date-pickers#date-pickers-allowed-dates Update I try to testing for make sure like

Is allowedDate not usable for async or ajax on the vuetify?

删除回忆录丶 提交于 2020-02-25 13:24:13
问题 I want to ask methods: { allowedDates(date) { console.log(date) } }, it will console.log all date on every month selected But if I add script ajax/async like this : methods: { allowedDates(date) { console.log(date) this.getData({appDate: date}); // this is async/call ajax on the vuex store } }, it's async without stopping is allowedDate not usable for async or ajax? docs : https://vuetifyjs.com/en/components/date-pickers#date-pickers-allowed-dates Update I try to testing for make sure like

Is allowedDate not usable for async or ajax on the vuetify?

孤街浪徒 提交于 2020-02-25 13:24:05
问题 I want to ask methods: { allowedDates(date) { console.log(date) } }, it will console.log all date on every month selected But if I add script ajax/async like this : methods: { allowedDates(date) { console.log(date) this.getData({appDate: date}); // this is async/call ajax on the vuex store } }, it's async without stopping is allowedDate not usable for async or ajax? docs : https://vuetifyjs.com/en/components/date-pickers#date-pickers-allowed-dates Update I try to testing for make sure like

How do you display a name in v-select for a vue-dropdown?

倾然丶 夕夏残阳落幕 提交于 2020-02-25 10:08:48
问题 Im dynamically rendering a V-select in my vue-app by a computed property in my component, but my select is populated with [object Object] instead of the values. How can I set the name-property? Am I doing this wrong? The dropdown is its own component: <template> <v-select :items="listOfCompanys" label="Lokation" item-value="name" item-text="name" single-line bottom ></v-select> </template> <script> export default { name: 'companydropdown', computed: { listOfCompanys () { return this.$store

How to query nested data in mongoose model

北城余情 提交于 2020-02-25 04:11:06
问题 I am attempting to build a Vue.js app with a MEVN stack backend and Vuex. I am configuring my Vuex action handler with a GET request that prompts a corresponding Express GET route to query data nested in Mongoose. A username is passed into the handler as an argument and appended to the GET request URL as a parameter: actions: { loadPosts: async (context, username) => { console.log(username) let uri = `http://localhost:4000/posts/currentuser?username=${username}`; const response = await axios

vuex基础 (三) 01-mutations——修改数据-可看成事件,在src-main.js中的store声明的vuex实例中进行定义

对着背影说爱祢 提交于 2020-02-25 00:34:44
03-vuex基础-mutations——修改数据,在src-main.js中的store声明的vuex实例中进行定义 修改数据 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。 Vuex 中的 mutation 非常 类似于事件 :每个 mutation 都有一个字符串的 事件类型 (type) 和 一个 回调函数 (handler)。这个回调函数就是我们实际进行状态更改的地方,并且它会接受 state 作为第一个参数: 网址: https://vuex.vuejs.org/zh/guide/mutations.html 申明: 第一步:在src/main.js中:申明修改数据 //初始化vuex 里面是配置项 const store = new Vuex.Store({ //申明数据 state:{ //申明数据,相当于vue实例中的data count:1 } //修改数据 + mutations: { // 改变数据 // 1. 没有参数 自增 count 数据 + // increment (state) { + // state.count++ + // } // 2. 使用参数 payload-形参,载荷( 运输数据 ) 可以传参数的写法 + increment (state, payload) { + // payload ====>

vuex简单介绍-官网

不问归期 提交于 2020-02-24 13:00:02
  vuex为状态管理器,主要用于全局状态管理,方便组件间的状态共享。其主要涉及 Store 、Mutation 、Action 、Getter vuex思想: 通过定义和隔离状态管理中的各种概念并通过强制规则维持视图和状态的独立性,代码更结构化且更易维护。 state:用来数据共享数据存储 mutation:用来注册改变数据状态 getters:用来对共享数据进行过滤操作 action:解决异步改变共享数据 state 驱动应用的数据源 view 以声明方式将state映射到视图 actions 响应在view上的用户输入导致的状态变化 每一个vuex应用的核心就是store仓库,即一个容器,其包含着应用中的大部分的状态state。 vuex的状态存储是响应式的:当vue组件从store中读取状态时,若store中的状态发生变化,则相应的组件也会相应地得到高效更新。 不能直接改变store中的状态:改变store中状态的唯一途径即是显示地提交mutation。 state: vuex使用单一状态树,即一个对象包含了全部的应用层级状态,唯一数据源,每一个应用仅包含一个store实例。 vuex状态存储是响应式的,从store实例中读取状态最简单方法是在计算属性中返回某个状态: Getter: getter的返回值会根据它的依赖被缓存起来,只有当它的依赖值发生了改变才会被重新计算。

从头开始学习Vuex

让人想犯罪 __ 提交于 2020-02-24 12:57:54
一、前言 当我们的应用遇到多个组件共享状态时,会需要多个组件依赖于同一状态抑或是来自不同视图的行为需要变更同一状态。以前的解决办法: a.将数据以及操作数据的行为都定义在父组件; b.将数据以及操作数据的行为传递给需要的各个子组件(有可能需要多级传递) 传参的方法对于多层嵌套的组件将会非常繁琐,并且对于兄弟组件间的状态传递无能为力。在搭建下面页面时,你可能会对 vue 组件之间的通信感到崩溃 ,特别是非父子组件之间通信。此时就应该使用vuex,轻松可以搞定组件间通信问题。 二、什么是Vuex Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。这里的关键在于集中式存储管理。 简单来说,对 vue 应用中多个组件的共享状态进行集中式的管理(读/写) 。 三、Vuex的原理是什么 1.简要介绍Vuex原理 Vuex实现了一个单向数据流,在全局拥有一个State存放数据,当组件要更改State中的数据时,必须通过Mutation进行,Mutation同时提供了订阅者模式供外部插件调用获取State数据的更新。而当所有异步操作(常见于调用后端接口异步获取更新数据)或批量的同步操作需要走Action,但Action也是无法直接修改State的

vuex的常用属性及其特性

三世轮回 提交于 2020-02-23 01:23:07
1.什么是vuex? vuex就是为vue定制的状态化管理模式 2.vuex有哪些属性?以及他的作用是什么? (1)state :存储数据比如一些变量和对象 ,使用语法:this.$store.state (2)getters :可以认为是计算属性 (3)mutations: 用来更新state里面的数据 (4)actions :提交mutations而不是直接变更状态,actions可以包含任意异步操作 (5)modules : 可以把某个模块都能分割成具有state,actions ,mutations ,actions的作用 来源: CSDN 作者: qq_44929680 链接: https://blog.csdn.net/qq_44929680/article/details/104445625