All Projects → wakeupmypig → Vue Plan

wakeupmypig / Vue Plan

使用vue+vue-router+vuex+boostrap实现计划表系统

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Plan

Vue Cli Multipage Bootstrap
vue-cli-multipage-bootstrap demo with vue2+vue-router+vuex+bootstrap+markdown for learning vue2.0
Stars: ✭ 105 (+218.18%)
Mutual labels:  vue-cli, vuex, bootstrap, vue-router
Netease yanxuan
vue版网易严选,体验网易严选购物流程,线上访问:http://zhaoboy.bid/yanxuan/#/
Stars: ✭ 417 (+1163.64%)
Mutual labels:  vue-cli, vuex, vue-router
Manhuaren
vue2.0全家桶,仿漫画人官网(移动端)
Stars: ✭ 18 (-45.45%)
Mutual labels:  vue-cli, vuex, vue-router
Yesplaymusic
高颜值的第三方网易云播放器,支持 Windows / macOS / Linux
Stars: ✭ 12,981 (+39236.36%)
Mutual labels:  vue-cli, vuex, vue-router
Vue3 Jd H5
🔥 Based on vue3.0.0, vant3.0.0, vue-router v4.0.0-0, vuex^4.0.0-0, vue-cli3, mockjs, imitating Jingdong Taobao, mobile H5 e-commerce platform! 基于vue3.0.0 ,vant3.0.0,vue-router v4.0.0-0, vuex^4.0.0-0,vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台!
Stars: ✭ 328 (+893.94%)
Mutual labels:  vue-cli, vuex, vue-router
Lulumi Browser
Lulumi-browser is a lightweight browser coded with Vue.js 2 and Electron.
Stars: ✭ 367 (+1012.12%)
Mutual labels:  vue-cli, vuex, vue-router
Vue Music
基于vue2.0的网易云音乐播放器,api来自于NeteaseCloudMusicApi,v2.0为最新版本
Stars: ✭ 855 (+2490.91%)
Mutual labels:  vue-cli, vuex, vue-router
Vue Zhihu Daily
🤓使用vue编写的练手的知乎日报WebApp(iOS版)
Stars: ✭ 285 (+763.64%)
Mutual labels:  vue-cli, vuex, vue-router
Vue Develop Template
A Vue.js template that can support more than 100 thousand lines of code in our business, I hope it can help you too~
Stars: ✭ 481 (+1357.58%)
Mutual labels:  vue-cli, vuex, vue-router
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (+1406.06%)
Mutual labels:  vue-cli, vuex, vue-router
Vue Chat
📲 A web chat application. Vue + node(koa2) + Mysql + socket.io
Stars: ✭ 617 (+1769.7%)
Mutual labels:  vue-cli, vuex, vue-router
Cocomusic
a simple music player built by electron and vue
Stars: ✭ 937 (+2739.39%)
Mutual labels:  vue-cli, vuex, vue-router
Daza Frontend
[DEPRECATED]
Stars: ✭ 326 (+887.88%)
Mutual labels:  vue-cli, vuex, vue-router
Vue2 Echo
基于vue2 + vue-router + vuex 构建的一个音乐类单页面应用 —— echo回声
Stars: ✭ 408 (+1136.36%)
Mutual labels:  vue-cli, vuex, vue-router
Space Snake
A Desktop game built with Electron and Vue.js.
Stars: ✭ 289 (+775.76%)
Mutual labels:  vue-cli, vuex, vue-router
Vue2 News
基于vue2 + vue-router + vuex 构建的一个新闻类单页面应用 —— 今日头条(移动端)
Stars: ✭ 462 (+1300%)
Mutual labels:  vue-cli, vuex, vue-router
Vue Gok
vue2.0-王者荣耀助手
Stars: ✭ 27 (-18.18%)
Mutual labels:  vue-cli, vuex, vue-router
Column
Vue3.0+Typescript+axios+bootstrap+源码注释/博客专栏作品
Stars: ✭ 261 (+690.91%)
Mutual labels:  vuex, bootstrap, vue-router
Vue Admin Design
基于vue + elementUI的管理系统模板
Stars: ✭ 279 (+745.45%)
Mutual labels:  vue-cli, vuex, vue-router
Douban
Douban book website demo by server side render
Stars: ✭ 468 (+1318.18%)
Mutual labels:  vue-cli, vuex, vue-router

Vuex-状态管理

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态。

1.安装vue-cli

安装命令行工具

npm install vue-cli -g

选择模板

  • webpack
  • webpack-simple
  • browserify
  • browserify-simple
  • simple

2.生成项目

vue init <template-name>#版本号 <product-name>

3.安装依赖并启动

$ cd myApp && npm install 
$ npm run dev
$ npm install vuex --save

4.安装调试工具dev-tool

https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd

5.单向数据流

  • state,驱动应用的数据源;
  • view,以声明方式将state映射到视图;
  • actions,响应在view上的用户输入导致的状态变化。

6.组件共享状态

  • 多个视图依赖于同一状态。
  • 来自不同视图的行为需要变更同一状态。

7.State-状态

单一状态树:用一个对象就包含了全部的应用层级状态。这个对象就是State,整个应用只能包含一个store的实例。

使用vuex创建状态,在App.vue下实现计数功能

<div id="app">
       <!--count应该归state管理-->
       计数器 {{count}}
       <button>增加</button>
</div>

创建store

$ cd src && mkdir store
$ cd store && touch index.js
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const state = {
  count:0
};
export const store = new Vuex.Store({
  state
});

在main.js中引入store

import {store} from './store'
new Vue({
  el: '#app',
  router,
  store,
  ...App
});

在页面上展示count

computed:{
    count(){
        return this.$store.state.count;
    }
}

辅助函数mapState可以简化写法

computed:{
    ...mapState([ // 不更改数据名
        'count'
    ])
    ...mapState({ // 更改数据名
      count:'count'
    })
}

8.Mutations-突变

更改Vuex中store的数据,只能通过提交mutation,每个mutation都有一个type和回调函数,回调函数中的参数就是当前store中的state

创建mutations

const INCREMENT = 'increment';
const mutations = {
  [INCREMENT](state,n){
    state.count += n;
  }
};
export const store = new Vuex.Store({
  state,
  mutations
});

更改页面count

<button @click="add">增加</button>
methods:{
    add(){
        this.$store.commit('increment',1);
    }
}

辅助函数`mapMutations可以简化写法

import {mapState,mapMutations} from 'vuex';
methods:{
    add(){
        this.increment(2);
    },
    ...mapMutations([
      'increment'
    ])
}

mutation只能写同步方法,一般是通过action中的commit提交到mutation中,我们一般只需派发action即可

9.Actions

  • Action提交的是mutation,不能直接更改状态
  • Action可以包含异步操作

通过action提交到mutation中

const actions = {
  [INCREMENT]({commit},n){
    commit(INCREMENT,n)
  }
};
export const store = new Vuex.Store({
  state,
  mutations,
  actions
});

直接使用mapActions简化操作

import {mapState,mapMutations,mapActions} from 'vuex';
methods:{
    add(){
        this.increment(1);
    },
    ...mapActions([
        'increment'
    ])
}

10.Getters

Vuex 允许我们在 store 中定义『getters』(可以认为是 store 的计算属性)。Getters 接受 state 作为其第一个参数:

想判断当前count是奇数还是偶数

const getters = {
  computeCount(state){
    return state.count%2==0?'偶数':'奇数'
  }
};
export const store = new Vuex.Store({
  state,
  mutations,
  actions,
  getters
});

直接使用mapGetters简化操作

import {mapState,mapMutations,mapActions,mapGetters} from 'vuex';
computed:{
    ...mapGetters([
        'computeCount'
    ])
},

在页面上将变量取出

{{count}}

vue-plain

A Vue.js project

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

For detailed explanation on how things work, checkout the guide and docs for vue-loader.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].