【心无旁骛】vuex-simple

这个算是一个小的demo嘛,先放上开源github地址:https://github.com/sascha245/vuex-simple
倒是可以先看下效果

呃呃,因为这个项目所在的目录与平时我们一般项目写在src中不同,我甚至怀疑这个本身其实是一个插件,这个demo只是其中的测试项目。
先看下项目目录

首先还是从基础文件进入项目

//main.ts
import 'reflect-metadata';

import Vue from 'vue';
import VueTypedi from 'vue-typedi';

import App from './App.vue';
import router from './router';
import store from './store';

Vue.config.productionTip = false;
Vue.use(VueTypedi);

new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app');
//samples\router.ts
import Vue from "vue";
import Router from "vue-router";

import About from "./views/About";
import Home from "./views/Home";

Vue.use(Router);

export default new Router({
  routes: [
    {
      component: Home,
      name: "home",
      path: "/",
    },
    {
      component: About,
      name: "about",
      path: "/about",
    }
  ]
});


这个里面比较有意思的是分离了ts文件,其实应该说就像是js文件也可以这样分解啊,不过这个算是打开了我的思路
接下来我们看核心内容home页面
我们进一步进行分析,发现减这个行为是比较独立的,先看减数
state中给其定义了不同的module,比如my1可以看做是核心的store

import { Module, State } from '../../../../src';
import { MyModule } from '../my';

export class TestState {
  @Module()
  public my1 = new MyModule(5);

  @Module()
  public my2 = new MyModule();

  @State()
  public counter: number = 10;

  @State()
  public name: string = 'Will';
}
//samples\store\modules\my.ts
import { Mutation, State } from '../../../src';

export class MyModule {
  @State()
  public counter: number = 0;

  @Mutation()
  public increment() {
    this.counter++;
  }

  constructor(counter = 0) {
    this.counter = counter;
  }
}
//samples\store\modules\test\getters.ts
import { Getter } from '../../../../src';
import { TestState } from './state';

export class TestGetters extends TestState {
  @Getter()
  public get cachedGetter() {
    return {
      item: this.counter + 100
    };
  }

  @Getter()
  public get total() {
    return this.counter + this.my1.counter + this.my2.counter;
  }

  public get normalGetter() {
    return {
      item: this.counter + 100
    };
  }
}
//samples\store\modules\test\mutations.ts
import { Mutation } from '../../../../src';
import { TestGetters } from './getters';

export class TestMutations extends TestGetters {
  @Mutation()
  public setCounter(count: number) {
    this.counter = count;
  }

  @Mutation()
  public increment() {
    this.counter++;
  }
}
//samples\store\store.ts
import { Action, Getter, Module, Mutation, State } from '../../src';
import { MyModule } from './modules/my';
import { TestModule } from './modules/test';
import { TodoModule } from './modules/todo';

export class MyStore {
  @Module()
  public my = new MyModule(20);

  @Module()
  public test = new TestModule();

  @Module()
  public todo = new TodoModule();

  @State()
  public version = '2.0.0';

  @State()
  public rootCounter = 0;

  @Getter()
  public get aRootCounter() {
    return this.rootCounter;
  }

  /**
   * Getter example with method style access
   */
  @Getter()
  public get numberButIncreased() {
    return (nb: number) => {
      return nb + 1;
    };
  }

  @Mutation()
  public incrementRootCounter() {
    this.rootCounter += 1;
  }

  @Action()
  public async actionIncrementRootCounter() {
    await new Promise(r => setTimeout(r, 1000));
    this.incrementRootCounter();
  }
}

后记:我数据流向还是没有弄清除

原文地址:https://www.cnblogs.com/smart-girl/p/11250532.html

时间: 2024-08-12 19:38:18

【心无旁骛】vuex-simple的相关文章

初译 Support Vector Machines:A Simple Tutorial(一)

从本次开始我将开始尝试着逐章翻译一下 Alexey Nefedov的<Support Vector Machines:A Simple Tutorial>这本教材,这可是我们导师极力推荐的SVM教材,看了好久一直感觉一脸懵逼,索性开坑翻译一下吧,也当是加深理解,毕竟我也是一知半解,如果翻译的有不对的地方还望大佬们斧正,欢迎提意见,欢迎讨论. 嗯,就是这样. (一)Introduction 在本章节中将会介绍一些用于定义支持向量机(SVM)的基础的概念,这些概念对于理解SVM至关重要,假定读者了

ubuntu16.04下安装NS-2.35以及对simple例的理解

本人是在VMWare上安装的ubuntu16.04版本,然后安装NS2.35. 1.下载ns2的安装包,这里我选择的是ns-allinone-2.35.tar.gz压缩格式的all in one安装包,all in one 安装包包含所有的组件,比较方便,另附下载地址: http://www.isi.edu/nsnam/ns/ns-build.html 2.安装前要先进行一些准备工作进行配置环境,输入如下代码: $sudo apt-get install build-essential $sud

[bzoj3489]A simple rmq problem

本题既不是rmq也不会simple(对我这种蒟蒻而言) 一开始只能想到树套树套树TAT然后看了看数据范围果断滚去膜拜题解. 然后才知道预先排序一下可以弄掉一个log.不过得写可持久化线段树套可持久化线段树.. 然后愉悦的开码了...感人的是竟然不用调...更感人的是交上去直接tle了. 然后从网上找了别人的代码(方法一样)发现同样的数据我要跑6s+..标称只要2s+.. 之后各种卡常还是慢了一倍TAT...最后自己写个max函数就和标程一样快了TAT这几天怎么总是出些奇怪的状况QAQ. 本来故事

地理数据可视化:Simple,Not Easy

如果要给2015年的地理信息行业打一个标签,地理大数据一定是其中之一.在信息技术飞速发展的今天,“大数据”作为一种潮流铺天盖地的席卷了各行各业,从央视的春运迁徙图到旅游热点预测,从大数据工程师奇货可居到马云布道“DT”时代,“大数据”被推到了一个前所未有的高度,连国家领导人出访演讲都言必称大数据.地理信息数据天生具有大数据属性,作为整天和地理信息数据打交道的地信人自然不甘落后,地理大数据概念脱颖而出. 地理大数据是什么?大体来说就是把社会经济.自然资源.商业信息等但凡具有一点空间维度的数据一股脑

简单工厂模式( Simple Factory Pattern )

1. 简单工厂模式( Simple Factory Pattern ) 1.1. 模式动机 考虑一个简单的软件应用场景,一个软件系统可以提供多个外观不同的按钮(如圆形按钮.矩形按钮.菱形按钮等), 这些按钮都源自同一个基类,不过在继承基类后不同的子类修改了部分属性从而使得它们可以呈现不同的外观,如果我们希望在使用这些按钮时,不需要知道这些具体按钮类的名字,只需要知道表示该按钮类的一个参数,并提供一个调用方便的方法,把该参数传入方法即可返回一个相应的按钮对象,此时,就可以使用简单工厂模式. 1.2

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

hdu 4974 A simple water problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or

hdu 4975 A simple Gaussian elimination problem.(网络流,判断矩阵是否存在)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One day, he drew a table with several rows and columns, randomly wrote numbers on each elements of the table. Then he counted the sum of each row and col

E - A Simple Problem with Integers

#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; #define N 100002 struct node { int l,r; long long lz,w; }q[4*N]; void pushup(int rt) { q[rt].w=q[rt*2].w+q[rt*2+1].w; } void pushdo

Simple Automated Backups for MongoDB Replica Sets

There are a bunch of different methods you can use to back up your MongoDB data, but if you want to avoid downtime and/or potential performance degradation, the most common advice seems to be that you should simply do all your backups on a slave. Thi