GithubHelp home page GithubHelp logo

说明

非常简单的一个vue2 + vuex的项目,整个流程一目了然,麻雀虽小,五脏俱全,适合作为入门练习。

如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢! ^_^

或者您可以 "follow" 一下,我会不断开源更多的有趣的项目

如有问题请直接在 Issues 中提,或者您发现问题并有非常好的解决方案,欢迎 PR 👍

开发环境 macOS 10.12.3 Chrome 56 nodejs 6.10.0

这个项目主要用于 vue2 + vuex 的入门练习,另外推荐一个 vue2 比较复杂的大型项目,覆盖了vuejs大部分的知识点。目前项目已经完成。地址在这里

项目运行(nodejs 6.0+)

# 克隆到本地
git clone https://github.com/bailicangdu/vue2-happyfri.git

# 进入文件夹
cd vue2-happyfri

# 安装依赖
npm install 或 yarn(推荐)

# 开启本地服务器localhost:8088
npm run dev

# 发布环境
npm run build

效果演示

demo地址(请用chrome手机模式预览)

移动端扫描下方二维码

路由配置

import App from '../App'

export default [{
    path: '/',
    component: App,
    children: [{
        path: '',
        component: r => require.ensure([], () => r(require('../page/home')), 'home')
    }, {
        path: '/item',
        component: r => require.ensure([], () => r(require('../page/item')), 'item')
    }, {
        path: '/score',
        component: r => require.ensure([], () => r(require('../page/score')), 'score')
    }]
}]

配置actions

import ajax from '../config/ajax'

export default {
	addNum({ commit, state }, id) {
		//点击下一题,记录答案id,判断是否是最后一题,如果不是则跳转下一题
		commit('REMBER_ANSWER', id);
		if (state.itemNum < state.itemDetail.length) {
			commit('ADD_ITEMNUM', 1);
		}
	},
	//初始化信息
	initializeData({ commit }) {
		commit('INITIALIZE_DATA');
	}
}

mutations

const ADD_ITEMNUM = 'ADD_ITEMNUM'
const REMBER_ANSWER = 'REMBER_ANSWER'
const REMBER_TIME = 'REMBER_TIME'
const INITIALIZE_DATA = 'INITIALIZE_DATA'
export default {
	//点击进入下一题
	[ADD_ITEMNUM](state, payload) {
		state.itemNum += payload.num;
	},
	//记录答案
	[REMBER_ANSWER](state, payload) {
		state.answerid[state.itemNum] = payload.id;
	},
	/*
	记录做题时间
	 */
	[REMBER_TIME](state) {
		state.timer = setInterval(() => {
			state.allTime++;
		}, 1000)
	},
	/*
	初始化信息,
	 */
	[INITIALIZE_DATA](state) {
		state.itemNum = 1;
		state.allTime = 0;
	},
}

创建store

import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'


Vue.use(Vuex)

const state = {
	level: '第一周',
	itemNum: 1,
	allTime: 0,
	timer: '',
	itemDetail: [],
	answerid: {}
}

export default new Vuex.Store({
	state,
	actions,
	mutations
})

创建vue实例

import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/router'
import store from './store/'

Vue.use(VueRouter)
const router = new VueRouter({
	routes
})

new Vue({
	router,
	store,
}).$mount('#app')

qwe104's Projects

download icon download

🔴蓝灯最新版本下载 https://github.com/getlantern/download 🔴 Lantern Latest Download https://github.com/getlantern/lantern/releases/tag/latest 🔴

dps icon dps

:tangerine: a way to make skeleton screen, 一种自动生成网页骨架屏的方式

draggable icon draggable

The JavaScript Drag & Drop library your grandparents warned you about.

dragui icon dragui

基于vuedraggable.js + uni 的可视化拖拽编程,自动生成项目,自动生成代码,自行导入第三方组件

dropzone icon dropzone

Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.(文件拖拽上传)

druid icon druid

Apache Druid: a high performance real-time analytics database.

dva icon dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)

dynamics.js icon dynamics.js

Javascript library to create physics-based animations 创建物理运动动画

easy-mock icon easy-mock

A persistent service that generates mock data quickly and provids visualization view.

easy-mock-cli icon easy-mock-cli

Create api.js for Easy-Mock. https://easy-mock.github.io/easy-mock-cli/

easy-monitor icon easy-monitor

企业级 Node.js 应用性能监控与线上故障定位解决方案

easy-pie-chart icon easy-pie-chart

easy pie chart is a lightweight plugin to draw simple, animated pie charts for single values(新型的EASY饼图数据统计Jquery插件)

easy-rl icon easy-rl

强化学习中文教程(蘑菇书),在线阅读地址:https://datawhalechina.github.io/easy-rl/

easy12306 icon easy12306

使用机器学习算法完成对12306验证码的自动识别

easyhanzi icon easyhanzi

“直书”—基于华为HMS Core ML Kit的人工智能趣学汉字小程序。 搭载拍照识别、语音识别、AI翻译、语音生成等人工智能黑科技,外国人也可轻松上手,即查即用,一站式掌握汉字音、形、写、义。

easyocr icon easyocr

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.

easyspider icon easyspider

A visual no-code/code-free web crawler/spider一个可视化爬虫软件,可以无代码图形化设计和执行的爬虫任务

easytimer.js icon easytimer.js

Easy to use Timer/Chronometer/Countdown library compatible with AMD and NodeJS(计时器)

echarts icon echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser

echo icon echo

Lazy-loading images with data-* attributes 图片懒加载 不依赖jquery

edex-ui icon edex-ui

A cross-platform, customizable science fiction terminal emulator with advanced monitoring & touchscreen support.

editor.js icon editor.js

A block-styled editor with clean JSON output

electron icon electron

Build cross platform desktop apps with JavaScript, HTML, and CSS

eleme icon eleme

vue2 +vue-router2 + es6 +webpack 高仿饿了么app商家详情,demo:http://liangxiaojuan.github.io/elem/index#/goods 还有我最新的实战项目,点它=》

element icon element

A Vue.js 2.0 UI Toolkit for Web Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的组件库,提供了配套设计资源,帮助你的网站快速成型。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.