1.1.0 • Published 5 years ago

n-keep-alive v1.1.0

Weekly downloads
85
License
-
Repository
github
Last release
5 years ago

nuxt-keep-alive

封装了nuxt.js<nuxt-child>

插件内部,通过动态更新nuxt-childkeep-alive-props,实现了前进更新数据,保存当前页面后退读取记录,清除当前页面

a->b->c

a页面进入b页面刷新b页面数据,c页面返回b页面读取b页面数据

安装

$ npm install n-keep-alive

使用

  1. /plugins/plugins.js中引入

Vue.use(NKeepAlive,option) 传入插件,和配置option

import NKeepAlive from 'n-keep-alive'
// keep-alive插件
export default ({ app }) => {
  Vue.use(NKeepAlive, {
    App: app, // 实例
    storeModulesName: 'NKeepAlive', // 库名
    includes: [
      {
        name: 'HomeParentList',
        path: '/keep-alive/parent-list'
      }
    ]
  })
}
window.vm = new Vue()
  1. /store/index.js中引入

引入仓库,指定key,这里keyNKeepAlive

import Vue from 'vue'
import Vuex from 'vuex'
import NKeepAlive from 'n-keep-alive'

Vue.use(Vuex)

const store = () =>
  new Vuex.Store({
    modules: {
      NKeepAlive: NKeepAlive.store
    },
    strict: process.env.NODE_ENV !== 'production'
  })

export default store
  1. 页面index.vue中使用组件<NKAlive></NKAlive>

注意: 把<NKAlive></NKAlive>当做<nuxt-child></nuxt-child>就可以了

<template>
  <div>
    <NKAlive/>
  </div>
</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
    };
  },
};
</script>

<style lang="scss" scoped>
</style>

特点

  1. 前进更新数据,保存当前页面

  2. 后退读取记录,清除当前页面

配置

option

参数描述类型是否必传默认
App实例对象Objecttrue--
storeModulesNamestore中,引入仓库的keyStringtrue--
includes需要配置的页面Arrayfalse[]
  • includes子配置项
参数描述类型是否必传默认
path页面路径Stringtrue--
name页面/组件暴露出的nameStringtrue--

注意

由于nuxt.js在使用当中,本身就存在一定问题,建议通过data来记录页面高度

本插件只是优化了<nuxt-child>,实现了自动判断传入的配置页面是否需要激活keep-alive

推荐配合cube-uicube-scroll组件

////////////////////////////////////////////////////////////////////
//                            _ooOoo_                             //
//                           o8888888o                            //
//                           88" . "88                            //
//                          (\ ^   ^ |)                           //
//                           O\  -  |O                            //
//                        ____/`---'\____                         //
//                      .'  \\|     |//  `.                       //
//                     /  \\|||  :  |||//  \                      //
//                    /  _||||| -:- |||||-  \                     //
//                    |   | \\\  -  /// |   |                     //
//                    | \_|  ''\---/''  |   |                     //
//                    \  .-\__  `-`  ___/-. /                     //
//                  ___`. .'  /--.--\  `. .`___                   //
//                ."" '<  `.___\_<|>_/___.'  >'"".                //
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |               //
//              \  \ `-.   \_ __\ /__ _/   .-` /  /               //
//        ========`-.____`-.___\_____/___.-`____.-'========       //
//                             `=---='                            //
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      //
//         佛祖保佑       永无BUG        永不修改                   //
////////////////////////////////////////////////////////////////////
1.1.0

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago