├── static
└── .gitkeep
├── .eslintignore
├── config
├── prod.env.js
├── dev.env.js
└── index.js
├── src
├── store
│ ├── action.js
│ ├── getters.js
│ ├── mutation-types.js
│ ├── mutations.js
│ └── index.js
├── components
│ └── card.vue
├── pages
│ ├── comment
│ │ ├── main.js
│ │ └── index.vue
│ └── index
│ │ ├── main.js
│ │ └── index.vue
├── utils
│ └── index.js
├── App.vue
└── main.js
├── .editorconfig
├── .gitignore
├── index.html
├── .postcssrc.js
├── .babelrc
├── README.md
├── .eslintrc.js
└── package.json
/static/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | }
4 |
--------------------------------------------------------------------------------
/src/store/action.js:
--------------------------------------------------------------------------------
1 | import {
2 |
3 | } from './mutation-types.js'
4 |
5 | export default {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/store/getters.js:
--------------------------------------------------------------------------------
1 | export default {
2 | // user: state => {
3 | // return state.userInfo
4 | // }
5 | }
6 |
--------------------------------------------------------------------------------
/src/store/mutation-types.js:
--------------------------------------------------------------------------------
1 | export const TEST = 'TEST' // 这是测试的
2 | export const USER_INFO = 'USER_INFO' // 这是也是测试的...
3 |
--------------------------------------------------------------------------------
/config/dev.env.js:
--------------------------------------------------------------------------------
1 | var merge = require('webpack-merge')
2 | var prodEnv = require('./prod.env')
3 |
4 | module.exports = merge(prodEnv, {
5 | NODE_ENV: '"development"'
6 | })
7 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | *.suo
11 | *.ntvs*
12 | *.njsproj
13 | *.sln
14 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | c2b-weixin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/store/mutations.js:
--------------------------------------------------------------------------------
1 | import {
2 | TEST,
3 | USER_INFO
4 | } from './mutation-types.js'
5 |
6 | export default {
7 | [TEST] (state, v) {
8 | state.test = v
9 | },
10 | [USER_INFO] (state, v) {
11 | state.userInfo = v
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {},
7 | "postcss-mpvue-wxss": {}
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/components/card.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
20 |
--------------------------------------------------------------------------------
/src/pages/comment/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './index'
3 |
4 | const app = new Vue(App)
5 | app.$mount()
6 | export default {
7 | config: { // 会生成json文件,页面里面的配置在此处配置。
8 | navigationBarTitleText: '名字'
9 | // navigationBarBackgroundColor: '#B3D4DB'
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/pages/index/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './index'
3 |
4 | const app = new Vue(App)
5 | app.$mount()
6 | export default {
7 | config: { // 会生成json文件,页面里面的配置在此处配置。
8 | // navigationBarTitleText: '名字'
9 | // navigationBarBackgroundColor: '#B3D4DB'
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/pages/comment/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
22 |
23 |
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # weixin
2 |
3 | > mpvue-vuex-persistedstate
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/src/utils/index.js:
--------------------------------------------------------------------------------
1 | function formatNumber (n) {
2 | const str = n.toString()
3 | return str[1] ? str : `0${str}`
4 | }
5 |
6 | export function formatTime (date) {
7 | const year = date.getFullYear()
8 | const month = date.getMonth() + 1
9 | const day = date.getDate()
10 |
11 | const hour = date.getHours()
12 | const minute = date.getMinutes()
13 | const second = date.getSeconds()
14 |
15 | const t1 = [year, month, day].map(formatNumber).join('/')
16 | const t2 = [hour, minute, second].map(formatNumber).join(':')
17 |
18 | return `${t1} ${t2}`
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 |
4 | import createPersistedState from 'vuex-persistedstate'
5 |
6 | import mutations from './mutations'
7 | import actions from './action'
8 | import getters from './getters'
9 |
10 | Vue.use(Vuex)
11 |
12 | const state = {
13 | test: 0,
14 | userInfo: {}
15 | }
16 |
17 | export default new Vuex.Store({
18 | state,
19 | getters,
20 | actions,
21 | mutations,
22 | plugins: [
23 | createPersistedState({
24 | storage: {
25 | getItem: key => wx.getStorageSync(key),
26 | setItem: (key, value) => wx.setStorageSync(key, value),
27 | removeItem: key => wx.clearStorage()
28 | }
29 | })
30 | ]
31 | })
32 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
13 |
14 |
32 |
--------------------------------------------------------------------------------
/src/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | click me
5 |
6 |
7 |
8 |
9 |
10 |
35 |
36 |
40 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 | import store from './store'
4 |
5 | Vue.config.productionTip = false
6 | App.mpType = 'app'
7 |
8 | Vue.prototype.$store = store
9 |
10 | const app = new Vue(App)
11 | app.$mount()
12 |
13 | export default {
14 | // 这个字段走 app.json
15 | config: {
16 | pages: ['^pages/index/index'], // 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
17 | window: {
18 | backgroundTextStyle: 'light',
19 | navigationBarBackgroundColor: '#fff',
20 | navigationBarTitleText: 'WeChat',
21 | navigationBarTextStyle: 'black'
22 | },
23 | tabBar: {
24 | list: [
25 | {
26 | 'pagePath': 'pages/index/index',
27 | 'text': '首页'
28 | },
29 | {
30 | 'pagePath': 'pages/comment/comment',
31 | 'text': '评论'
32 | }
33 | ]
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parser: 'babel-eslint',
6 | parserOptions: {
7 | sourceType: 'module'
8 | },
9 | env: {
10 | browser: false,
11 | node: true,
12 | es6: true
13 | },
14 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
15 | extends: 'standard',
16 | // required to lint *.vue files
17 | plugins: [
18 | 'html'
19 | ],
20 | // add your custom rules here
21 | 'rules': {
22 | // allow paren-less arrow functions
23 | 'arrow-parens': 0,
24 | // allow async-await
25 | 'generator-star-spacing': 0,
26 | // allow debugger during development
27 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
28 | },
29 | globals: {
30 | App: true,
31 | Page: true,
32 | wx: true,
33 | getApp: true,
34 | getPage: true
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path')
3 |
4 | module.exports = {
5 | build: {
6 | env: require('./prod.env'),
7 | index: path.resolve(__dirname, '../dist/index.html'),
8 | assetsRoot: path.resolve(__dirname, '../dist'),
9 | assetsSubDirectory: 'static',
10 | assetsPublicPath: '/',
11 | productionSourceMap: false,
12 | // Gzip off by default as many popular static hosts such as
13 | // Surge or Netlify already gzip all static assets for you.
14 | // Before setting to `true`, make sure to:
15 | // npm install --save-dev compression-webpack-plugin
16 | productionGzip: false,
17 | productionGzipExtensions: ['js', 'css'],
18 | // Run the build command with an extra argument to
19 | // View the bundle analyzer report after build finishes:
20 | // `npm run build --report`
21 | // Set to `true` or `false` to always turn it on or off
22 | bundleAnalyzerReport: process.env.npm_config_report
23 | },
24 | dev: {
25 | env: require('./dev.env'),
26 | port: 8080,
27 | // 在小程序开发者工具中不需要自动打开浏览器
28 | autoOpenBrowser: false,
29 | assetsSubDirectory: 'static',
30 | assetsPublicPath: '/',
31 | proxyTable: {},
32 | // CSS Sourcemaps off by default because relative paths are "buggy"
33 | // with this option, according to the CSS-Loader README
34 | // (https://github.com/webpack/css-loader#sourcemaps)
35 | // In our experience, they generally work as expected,
36 | // just be aware of this issue when enabling this option.
37 | cssSourceMap: false
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mpvue-demo",
3 | "version": "1.0.0",
4 | "description": "微信小程序demo",
5 | "author": "zhoujian <758507292@qq.com>",
6 | "private": true,
7 | "scripts": {
8 | "dev": "node build/dev-server.js",
9 | "start": "node build/dev-server.js",
10 | "build": "node build/build.js",
11 | "lint": "eslint --ext .js,.vue src"
12 | },
13 | "dependencies": {
14 | "mpvue": "^1.0.1",
15 | "vuex": "^2.3.1",
16 | "vuex-persistedstate": "^2.4.2"
17 | },
18 | "devDependencies": {
19 | "autoprefixer": "^7.1.2",
20 | "babel-core": "^6.22.1",
21 | "babel-eslint": "^7.1.1",
22 | "babel-loader": "^7.1.1",
23 | "babel-plugin-transform-runtime": "^6.22.0",
24 | "babel-preset-env": "^1.3.2",
25 | "babel-preset-stage-2": "^6.22.0",
26 | "babel-register": "^6.22.0",
27 | "chalk": "^2.0.1",
28 | "connect-history-api-fallback": "^1.3.0",
29 | "copy-webpack-plugin": "^4.0.1",
30 | "css-loader": "^0.28.0",
31 | "cssnano": "^3.10.0",
32 | "eslint": "^3.19.0",
33 | "eslint-config-standard": "^6.2.1",
34 | "eslint-friendly-formatter": "^3.0.0",
35 | "eslint-loader": "^1.7.1",
36 | "eslint-plugin-html": "^3.0.0",
37 | "eslint-plugin-promise": "^3.4.0",
38 | "eslint-plugin-standard": "^2.0.1",
39 | "eventsource-polyfill": "^0.9.6",
40 | "express": "^4.14.1",
41 | "extract-text-webpack-plugin": "^2.0.0",
42 | "file-loader": "^0.11.1",
43 | "friendly-errors-webpack-plugin": "^1.1.3",
44 | "html-webpack-plugin": "^2.28.0",
45 | "http-proxy-middleware": "^0.17.3",
46 | "less": "^3.0.1",
47 | "less-loader": "^4.1.0",
48 | "mpvue-loader": "^1.0.2",
49 | "mpvue-template-compiler": "^1.0.1",
50 | "mpvue-webpack-target": "^1.0.0",
51 | "opn": "^5.1.0",
52 | "optimize-css-assets-webpack-plugin": "^2.0.0",
53 | "ora": "^1.2.0",
54 | "postcss-loader": "^2.0.6",
55 | "postcss-mpvue-wxss": "^1.0.0",
56 | "px2rpx-loader": "^0.1.8",
57 | "rimraf": "^2.6.0",
58 | "semver": "^5.3.0",
59 | "shelljs": "^0.7.6",
60 | "url-loader": "^0.5.8",
61 | "vue-style-loader": "^3.0.1",
62 | "webpack": "^2.6.1",
63 | "webpack-bundle-analyzer": "^2.2.1",
64 | "webpack-dev-middleware": "^1.10.0",
65 | "webpack-dev-middleware-hard-disk": "^1.10.0",
66 | "webpack-hot-middleware": "^2.18.0",
67 | "webpack-merge": "^4.1.0"
68 | },
69 | "engines": {
70 | "node": ">= 4.0.0",
71 | "npm": ">= 3.0.0"
72 | },
73 | "browserslist": [
74 | "> 1%",
75 | "last 2 versions",
76 | "not ie <= 8"
77 | ]
78 | }
79 |
--------------------------------------------------------------------------------