├── examples
└── demo
│ ├── public
│ ├── favicon.ico
│ └── index.html
│ ├── babel.config.js
│ ├── src
│ ├── main.js
│ ├── store
│ │ ├── modules
│ │ │ ├── user
│ │ │ │ └── store.js
│ │ │ └── product
│ │ │ │ └── store.js
│ │ └── index.js
│ └── App.vue
│ ├── .gitignore
│ ├── README.md
│ └── package.json
├── .babelrc.js
├── .travis.yml
├── .gitignore
├── .eslintrc.js
├── rollup.config.js
├── package.json
├── README.md
├── lib
└── vue-savedata.umd.js
├── packages
└── index.js
└── test
└── savedata.test.js
/examples/demo/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Banlangenn/vue-savedata/HEAD/examples/demo/public/favicon.ico
--------------------------------------------------------------------------------
/examples/demo/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@vue/app'
4 | ],
5 | //添加忽略项
6 | ignore: [
7 | './../../lib',
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/.babelrc.js:
--------------------------------------------------------------------------------
1 |
2 | module.exports = {
3 | "presets": [
4 | ["@babel/env",{
5 | "targets": {
6 | "ie": 9
7 | }
8 | }]
9 | ]
10 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "11"
5 |
6 | before_script:
7 | - npm install codecov --save-dev
8 | - npm run build
9 |
10 | script:
11 | - npm run test
12 | #指定分支,只有指定的分支提交时才会运行脚本
13 | branches:
14 | only:
15 | - master
16 |
--------------------------------------------------------------------------------
/examples/demo/src/main.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | import Vue from 'vue';
3 | import App from './App';
4 | import store from './store/index';
5 |
6 | Vue.config.productionTip = false;
7 |
8 | new Vue({
9 | store,
10 | render: h => h(App)
11 | }).$mount('#app');
12 |
--------------------------------------------------------------------------------
/examples/demo/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 | *.sw?
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | coverage
4 | tmp
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 | package-lock.json*
14 | yarn.lock*
15 |
16 | # Editor directories and files
17 | .idea
18 | .vscode
19 | *.suo
20 | *.ntvs*
21 | *.njsproj
22 | *.sln
23 | *.sw*
24 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | // extends: 'react-app',
3 | extends: 'eslint:recommended', // eslint 自带
4 | env: {
5 | node: true,
6 | es6: true,
7 | commonjs: true,
8 | },
9 | parserOptions: {
10 | "ecmaVersion": 2018
11 | },
12 | rules: {
13 | "no-console": 0,
14 | "indent": ['error', 4], //缩进风格
15 | },
16 | parser : "babel-eslint"
17 | }
--------------------------------------------------------------------------------
/examples/demo/src/store/modules/user/store.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | const user = {
3 | namespaced: true,
4 | state: {
5 | nickname: ''
6 | },
7 | mutations: {
8 | nickname(state, nickname) {
9 | state.nickname = nickname;
10 | }
11 | },
12 | actions: {
13 | setactnickname(context, nickname) {
14 | context.commit('nickname', nickname);
15 | }
16 | }
17 | };
18 |
19 | export default user;
20 |
--------------------------------------------------------------------------------
/examples/demo/README.md:
--------------------------------------------------------------------------------
1 | # demo
2 |
3 | ## Project setup
4 | ```
5 | yarn install
6 | ```
7 |
8 | ### Compiles and hot-reloads for development
9 | ```
10 | yarn run serve
11 | ```
12 |
13 | ### Compiles and minifies for production
14 | ```
15 | yarn run build
16 | ```
17 |
18 | ### Run your tests
19 | ```
20 | yarn run test
21 | ```
22 |
23 | ### Lints and fixes files
24 | ```
25 | yarn run lint
26 | ```
27 |
28 | ### Customize configuration
29 | See [Configuration Reference](https://cli.vuejs.org/config/).
30 |
--------------------------------------------------------------------------------
/examples/demo/src/store/modules/product/store.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | const productstore = {
3 | // namespaced: true,
4 | state: {
5 | brand: [],
6 | products: '1459856855',
7 | pictures: []
8 | },
9 | mutations: {
10 | nickname(state, nickname) {
11 | state.products = nickname;
12 | }
13 | },
14 | actions: {
15 | setactnickname(context, nickname) {
16 | context.commit('nickname', nickname);
17 | }
18 | }
19 | };
20 |
21 | export default productstore;
22 |
--------------------------------------------------------------------------------
/examples/demo/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | demo
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 |
2 | // rollup.config.js
3 | // import resolve from 'rollup-plugin-node-resolve';
4 | import babel from 'rollup-plugin-babel';
5 | import { terser } from 'rollup-plugin-terser'
6 | export default {
7 | input: './packages/index.js',
8 | output: {
9 | name: 'vue-savedata.umd',
10 | file: './lib/vue-savedata.umd.js',
11 | format: 'umd'
12 | },
13 | plugins: [
14 | babel({
15 | exclude: 'node_modules/**', // 只编译我们的源代码
16 | runtimeHelpers: true
17 | }),
18 | terser({
19 | compress: {
20 | pure_getters: true,
21 | unsafe: true,
22 | unsafe_comps: true,
23 | warnings: false
24 | }
25 | })
26 | ]
27 | };
--------------------------------------------------------------------------------
/examples/demo/src/App.vue:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 |
3 |
4 |
5 |
{{ this.$store.state.user.nickname }}
6 |
{{ this.$store.state.product.products }}
7 |
8 |
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/demo/src/store/index.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | import Vue from 'vue';
3 | import Vuex from 'vuex';
4 | import createPersisted from './../../../../lib/vue-savedata.umd';
5 | import user from './modules/user/store';
6 | import product from './modules/product/store';
7 | const persisted = createPersisted({
8 | saveName: 'aaa',
9 | ciphered: false,
10 | mode: 'LS',
11 | LS: [
12 | {
13 | module: user,
14 | storePath: 'user'
15 | },
16 | {
17 | module: product,
18 | storePath: 'product'
19 | },
20 | ]
21 | });
22 |
23 | // const persiste2 = createPersiste({
24 | // saveName: 'bbb',
25 | // ciphered: true,
26 | // mode: 'LS',
27 | // LS: [
28 | // {
29 | // module: user,
30 | // storePath: 'user'
31 | // },
32 | // ]
33 | // });
34 |
35 | Vue.use(Vuex);
36 | const store = new Vuex.Store({
37 | modules: {
38 | user,
39 | product
40 | },
41 | plugins: [ persisted ]
42 | });
43 |
44 | export default store;
45 |
--------------------------------------------------------------------------------
/examples/demo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "demo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build",
8 | "lint": "vue-cli-service lint"
9 | },
10 | "dependencies": {
11 | "core-js": "^2.6.5",
12 | "vue": "^2.6.10",
13 | "vuex": "^3.5.1"
14 | },
15 | "devDependencies": {
16 | "@vue/cli-plugin-babel": "^3.11.0",
17 | "@vue/cli-plugin-eslint": "^3.11.0",
18 | "@vue/cli-service": "^3.11.0",
19 | "babel-eslint": "^10.0.1",
20 | "eslint": "^5.16.0",
21 | "eslint-plugin-vue": "^5.0.0",
22 | "vue-template-compiler": "^2.6.10"
23 | },
24 | "eslintConfig": {
25 | "root": true,
26 | "env": {
27 | "node": true
28 | },
29 | "extends": [
30 | "plugin:vue/essential",
31 | "eslint:recommended"
32 | ],
33 | "rules": {},
34 | "parserOptions": {
35 | "parser": "babel-eslint"
36 | }
37 | },
38 | "postcss": {
39 | "plugins": {
40 | "autoprefixer": {}
41 | }
42 | },
43 | "browserslist": [
44 | "> 1%",
45 | "last 2 versions"
46 | ]
47 | }
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-savedata",
3 | "version": "2.0.5",
4 | "main": "./lib/vue-savedata.umd.js",
5 | "description": "vuex插件 指定数据持久化(配置简,性能佳,体积小)",
6 | "scripts": {
7 | "test": "jest && codecov",
8 | "test:l": "jest",
9 | "build": "rm -rf ./lib && rollup -c",
10 | "lint": "eslint packages test"
11 | },
12 | "jest": {
13 | "coverageDirectory": "./coverage/",
14 | "collectCoverage": true,
15 | "transform": {
16 | "^.+\\.js?$": "babel-jest"
17 | }
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/Banlangenn/vue-savedata"
22 | },
23 | "keywords": [
24 | "vuex",
25 | "persitste",
26 | "vue",
27 | "savedata"
28 | ],
29 | "author": "balangen",
30 | "license": "ISC",
31 | "devDependencies": {
32 | "@babel/core": "^7.3.4",
33 | "@babel/preset-env": "^7.3.4",
34 | "babel-eslint": "^10.0.3",
35 | "babel-jest": "^24.9.0",
36 | "eslint": "^5.16.0",
37 | "global": "^4.3.2",
38 | "jest": "^24.8.0",
39 | "pre-commit": "^1.2.2",
40 | "rollup": "^1.6.0",
41 | "rollup-plugin-babel": "^4.3.2",
42 | "rollup-plugin-terser": "^4.0.4",
43 | "rollup-plugin-uglify": "^6.0.2",
44 | "vue": "^2.5.20",
45 | "vuex": "^3.0.1"
46 | },
47 | "pre-commit": [
48 | "lint",
49 | "test:l"
50 | ]
51 | }
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # vue-savedata
3 | [](https://www.travis-ci.org/Banlangenn/vue-savedata) [](https://codecov.io/gh/Banlangenn/vue-savedata)
4 |
5 | vuex 指定【模块】的state持久化(配置简,性能佳,体积小: gzip压缩之后 1238字节 ≈ 1.2kb)
6 | ## updata 2.0.6
7 | * 修复ie9 ie10 报错问题
8 | * 添加 ciphertext密文支持
9 | * 添加 SS LS 支持数组 (每一个module要添加store中modules中)
10 | * 添加 默认储存位置配置
11 | * 支持 模块命名空间
12 | ## Requirements
13 |
14 | * [Vue.js](https://vuejs.org) (v2.0.0+)
15 | * [Vuex](http://vuex.vuejs.org) (v2.0.0+)
16 |
17 | ## Installation
18 |
19 | ```bash
20 | $ npm install vue-savedata
21 | $ yarn add vue-savedata
22 | ```
23 |
24 | ## Usage
25 |
26 | ```js
27 | import createPersiste from 'vue-savedata'
28 | // 默认全部持久化,你也可以通过一丢丢配置项,指定数据持久化
29 | const store = new Vuex.Store({
30 | // ...
31 | plugins: [createPersiste()],
32 | })
33 | ```
34 | ## API
35 |
36 | ### `createPersiste([options])`
37 | 下列选项(默认保存store中的每个数据到本地 )
38 | ### (`温馨提示`: LS即Localstorage本地存储, SS即sessionStorage本地存储, LS、SS可同时使用,也可单独使用 )
39 | 可以为您的特定需求配置插件:
40 | (参数都是可选的:有默认值)
41 | * `saveName `: 本地save的key 默认: savedata
42 | * `ciphertext `: 是不是密文存本地(base64) 默认 false
43 | * `mode `: 默认存储模式(LS,SS配置不存在时有效) 默认: LS
44 | * `MMD `: 模块 深度合并, 深度值 默认:2(如果出现数据丢失可以尝试把这个开高一点)
45 | * `SS