From f02bbd193b0c6c047a1c608300bd80d5fa816221 Mon Sep 17 00:00:00 2001 From: wanxiangming1994 Date: Tue, 3 Apr 2018 12:09:15 +0800 Subject: [PATCH] v1.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1,新增了noCacheList特性,支持指定某些name的页面不进行缓存 --- dist/vue-navigation.esm.js | 12 +++++++++--- dist/vue-navigation.esm.min.js | 2 +- dist/vue-navigation.umd.js | 12 +++++++++--- dist/vue-navigation.umd.min.js | 2 +- src/components/Navigation.js | 6 ++++-- src/index.js | 4 ++-- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/dist/vue-navigation.esm.js b/dist/vue-navigation.esm.js index d5b0f52..9b68328 100644 --- a/dist/vue-navigation.esm.js +++ b/dist/vue-navigation.esm.js @@ -183,6 +183,8 @@ var Navigator = (function (bus, store, moduleName, keyName) { }); var NavComponent = (function (keyName) { + var noCacheList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + return { name: 'navigation', abstract: true, @@ -230,7 +232,9 @@ var NavComponent = (function (keyName) { this.cache[key] = vnode; } } else { - this.cache[key] = vnode; + if (noCacheList.indexOf(this.$router.history.current.name) === -1) { + this.cache[key] = vnode; + } } vnode.data.keepAlive = true; } @@ -251,7 +255,9 @@ var index = { _ref$moduleName = _ref.moduleName, moduleName = _ref$moduleName === undefined ? 'navigation' : _ref$moduleName, _ref$keyName = _ref.keyName, - keyName = _ref$keyName === undefined ? 'VNK' : _ref$keyName; + keyName = _ref$keyName === undefined ? 'VNK' : _ref$keyName, + _ref$noCacheList = _ref.noCacheList, + noCacheList = _ref$noCacheList === undefined ? [] : _ref$noCacheList; if (!router) { console.error('vue-navigation need options: router'); @@ -288,7 +294,7 @@ var index = { replaceFlag = false; }); - Vue.component('navigation', NavComponent(keyName)); + Vue.component('navigation', NavComponent(keyName, noCacheList)); Vue.navigation = Vue.prototype.$navigation = { on: function on(event, callback) { diff --git a/dist/vue-navigation.esm.min.js b/dist/vue-navigation.esm.min.js index c57789c..bbba054 100644 --- a/dist/vue-navigation.esm.min.js +++ b/dist/vue-navigation.esm.min.js @@ -3,4 +3,4 @@ * https://github.com/zack24q/vue-navigation * Released under the MIT License. */ -function genKey(){return"xxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function getKey(e,t){return(e.name||e.path)+"?"+e.query[t]}function matches(e,t){return Array.isArray(e)?e.indexOf(t)>-1:"string"==typeof e?e.split(",").indexOf(t)>-1:!!isRegExp(e)&&e.test(t)}function isObjEqual(e,t){if(e===t)return!0;var n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;var r=!0,i=!1,a=void 0;try{for(var s,u=n[Symbol.iterator]();!(r=(s=u.next()).done);r=!0){var c=s.value;if(e[c]!==t[c])return!1}}catch(e){i=!0,a=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw a}}return!0}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var routes=[];window.sessionStorage.VUE_NAVIGATION&&(routes=JSON.parse(window.sessionStorage.VUE_NAVIGATION));var Routes=routes,Navigator=function(e,t,n,o){t&&t.registerModule(n,{state:{routes:Routes},mutations:{"navigation/FORWARD":function(e,t){t.to,t.from;var n=t.name;e.routes.push(n)},"navigation/BACK":function(e,t){t.to,t.from;var n=t.count;e.routes.splice(e.routes.length-n,n)},"navigation/REPLACE":function(e,t){t.to,t.from;var n=t.name;e.routes.splice(Routes.length-1,1,n)},"navigation/REFRESH":function(e,t){t.to,t.from},"navigation/RESET":function(e){e.routes.splice(0,e.routes.length)}}});var r=function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1]||null,a.name=o,t?t.commit("navigation/FORWARD",{to:a,from:s,name:o}):u.push(o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("forward",a,s)},i=function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1],a.name=u[u.length-1-o],t?t.commit("navigation/BACK",{to:a,from:s,count:o}):u.splice(Routes.length-o,o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("back",a,s)},a=function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1]||null,a.name=o,t?t.commit("navigation/REPLACE",{to:a,from:s,name:o}):u.splice(Routes.length-1,1,o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("replace",a,s)},s=function(o,r){var i={route:o},a={route:r},s=t?t.state[n].routes:Routes;i.name=a.name=s[s.length-1],t&&t.commit("navigation/REFRESH",{to:i,from:a}),e.$emit("refresh",i,a)};return{record:function(e,t,n){var u=getKey(e,o);if(n)a(u,e,t);else{var c=Routes.lastIndexOf(u);-1===c?r(u,e,t):c===Routes.length-1?s(e,t):i(Routes.length-1-c,e,t)}},reset:function(){t?t.commit("navigation/RESET"):Routes.splice(0,Routes.length),window.sessionStorage.VUE_NAVIGATION=JSON.stringify([]),e.$emit("reset")}}},NavComponent=function(e){return{name:"navigation",abstract:!0,props:{},data:function(){return{routes:Routes}},computed:{},watch:{routes:function(e){for(var t in this.cache)if(!matches(e,t)){var n=this.cache[t];n&&n.componentInstance.$destroy(),delete this.cache[t]}}},created:function(){this.cache={}},destroyed:function(){for(var e in this.cache){var t=this.cache[e];t&&t.componentInstance.$destroy()}},render:function(){var t=this.$slots.default?this.$slots.default[0]:null;if(t){t.key=t.key||(t.isComment?"comment":t.tag);var n=getKey(this.$route,e);-1===t.key.indexOf(n)&&(t.key="__navigation-"+n+"-"+t.key),this.cache[n]?t.key===this.cache[n].key?t.componentInstance=this.cache[n].componentInstance:(this.cache[n].componentInstance.$destroy(),this.cache[n]=t):this.cache[n]=t,t.data.keepAlive=!0}return t}}},_extends=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},n=t.router,o=t.store,r=t.moduleName,i=void 0===r?"navigation":r,a=t.keyName,s=void 0===a?"VNK":a;if(n){var u=new e,c=Navigator(u,o,i,s),f=n.replace.bind(n),l=!1;n.replace=function(e,t,n){l=!0,f(e,t,n)},n.beforeEach(function(e,t,n){if(e.query[s])n();else{var o=_extends({},e.query);e.path===t.path&&isObjEqual(_extends({},e.query,_defineProperty({},s,null)),_extends({},t.query,_defineProperty({},s,null)))&&t.query[s]?o[s]=t.query[s]:o[s]=genKey(),n({path:e.path,query:o,replace:l||!t.query[s]})}}),n.afterEach(function(e,t){c.record(e,t,l),l=!1}),e.component("navigation",NavComponent(s)),e.navigation=e.prototype.$navigation={on:function(e,t){u.$on(e,t)},once:function(e,t){u.$once(e,t)},off:function(e,t){u.$off(e,t)},getRoutes:function(){return Routes.slice()},cleanRoutes:function(){return c.reset()}}}else console.error("vue-navigation need options: router")}};export default index; \ No newline at end of file +var routes=[];window.sessionStorage.VUE_NAVIGATION&&(routes=JSON.parse(window.sessionStorage.VUE_NAVIGATION));var Routes=routes;function genKey(){return"xxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function getKey(e,t){return(e.name||e.path)+"?"+e.query[t]}function matches(e,t){return Array.isArray(e)?e.indexOf(t)>-1:"string"==typeof e?e.split(",").indexOf(t)>-1:!!isRegExp(e)&&e.test(t)}function isObjEqual(e,t){if(e===t)return!0;var n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;var r=!0,i=!1,a=void 0;try{for(var s,u=n[Symbol.iterator]();!(r=(s=u.next()).done);r=!0){var c=s.value;if(e[c]!==t[c])return!1}}catch(e){i=!0,a=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw a}}return!0}var Navigator=function(e,t,n,o){t&&t.registerModule(n,{state:{routes:Routes},mutations:{"navigation/FORWARD":function(e,t){t.to,t.from;var n=t.name;e.routes.push(n)},"navigation/BACK":function(e,t){t.to,t.from;var n=t.count;e.routes.splice(e.routes.length-n,n)},"navigation/REPLACE":function(e,t){t.to,t.from;var n=t.name;e.routes.splice(Routes.length-1,1,n)},"navigation/REFRESH":function(e,t){t.to,t.from},"navigation/RESET":function(e){e.routes.splice(0,e.routes.length)}}});return{record:function(r,i,a){var s=getKey(r,o);if(a)!function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1]||null,a.name=o,t?t.commit("navigation/REPLACE",{to:a,from:s,name:o}):u.splice(Routes.length-1,1,o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("replace",a,s)}(s,r,i);else{var u=Routes.lastIndexOf(s);-1===u?function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1]||null,a.name=o,t?t.commit("navigation/FORWARD",{to:a,from:s,name:o}):u.push(o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("forward",a,s)}(s,r,i):u===Routes.length-1?function(o,r){var i={route:o},a={route:r},s=t?t.state[n].routes:Routes;i.name=a.name=s[s.length-1],t&&t.commit("navigation/REFRESH",{to:i,from:a}),e.$emit("refresh",i,a)}(r,i):function(o,r,i){var a={route:r},s={route:i},u=t?t.state[n].routes:Routes;s.name=u[u.length-1],a.name=u[u.length-1-o],t?t.commit("navigation/BACK",{to:a,from:s,count:o}):u.splice(Routes.length-o,o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(u),e.$emit("back",a,s)}(Routes.length-1-u,r,i)}},reset:function(){t?t.commit("navigation/RESET"):Routes.splice(0,Routes.length),window.sessionStorage.VUE_NAVIGATION=JSON.stringify([]),e.$emit("reset")}}},NavComponent=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return{name:"navigation",abstract:!0,props:{},data:function(){return{routes:Routes}},computed:{},watch:{routes:function(e){for(var t in this.cache)if(!matches(e,t)){var n=this.cache[t];n&&n.componentInstance.$destroy(),delete this.cache[t]}}},created:function(){this.cache={}},destroyed:function(){for(var e in this.cache){var t=this.cache[e];t&&t.componentInstance.$destroy()}},render:function(){var n=this.$slots.default?this.$slots.default[0]:null;if(n){n.key=n.key||(n.isComment?"comment":n.tag);var o=getKey(this.$route,e);-1===n.key.indexOf(o)&&(n.key="__navigation-"+o+"-"+n.key),this.cache[o]?n.key===this.cache[o].key?n.componentInstance=this.cache[o].componentInstance:(this.cache[o].componentInstance.$destroy(),this.cache[o]=n):-1===t.indexOf(this.$router.history.current.name)&&(this.cache[o]=n),n.data.keepAlive=!0}return n}}},_extends=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},n=t.router,o=t.store,r=t.moduleName,i=void 0===r?"navigation":r,a=t.keyName,s=void 0===a?"VNK":a,u=t.noCacheList,c=void 0===u?[]:u;if(n){var f=new e,l=Navigator(f,o,i,s),h=n.replace.bind(n),g=!1;n.replace=function(e,t,n){g=!0,h(e,t,n)},n.beforeEach(function(e,t,n){if(e.query[s])n();else{var o=_extends({},e.query);e.path===t.path&&isObjEqual(_extends({},e.query,_defineProperty({},s,null)),_extends({},t.query,_defineProperty({},s,null)))&&t.query[s]?o[s]=t.query[s]:o[s]=genKey(),n({path:e.path,query:o,replace:g||!t.query[s]})}}),n.afterEach(function(e,t){l.record(e,t,g),g=!1}),e.component("navigation",NavComponent(s,c)),e.navigation=e.prototype.$navigation={on:function(e,t){f.$on(e,t)},once:function(e,t){f.$once(e,t)},off:function(e,t){f.$off(e,t)},getRoutes:function(){return Routes.slice()},cleanRoutes:function(){return l.reset()}}}else console.error("vue-navigation need options: router")}};export default index; \ No newline at end of file diff --git a/dist/vue-navigation.umd.js b/dist/vue-navigation.umd.js index 079780a..0c9f408 100644 --- a/dist/vue-navigation.umd.js +++ b/dist/vue-navigation.umd.js @@ -189,6 +189,8 @@ var Navigator = (function (bus, store, moduleName, keyName) { }); var NavComponent = (function (keyName) { + var noCacheList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + return { name: 'navigation', abstract: true, @@ -236,7 +238,9 @@ var NavComponent = (function (keyName) { this.cache[key] = vnode; } } else { - this.cache[key] = vnode; + if (noCacheList.indexOf(this.$router.history.current.name) === -1) { + this.cache[key] = vnode; + } } vnode.data.keepAlive = true; } @@ -257,7 +261,9 @@ var index = { _ref$moduleName = _ref.moduleName, moduleName = _ref$moduleName === undefined ? 'navigation' : _ref$moduleName, _ref$keyName = _ref.keyName, - keyName = _ref$keyName === undefined ? 'VNK' : _ref$keyName; + keyName = _ref$keyName === undefined ? 'VNK' : _ref$keyName, + _ref$noCacheList = _ref.noCacheList, + noCacheList = _ref$noCacheList === undefined ? [] : _ref$noCacheList; if (!router) { console.error('vue-navigation need options: router'); @@ -294,7 +300,7 @@ var index = { replaceFlag = false; }); - Vue.component('navigation', NavComponent(keyName)); + Vue.component('navigation', NavComponent(keyName, noCacheList)); Vue.navigation = Vue.prototype.$navigation = { on: function on(event, callback) { diff --git a/dist/vue-navigation.umd.min.js b/dist/vue-navigation.umd.min.js index bb57605..d734653 100644 --- a/dist/vue-navigation.umd.min.js +++ b/dist/vue-navigation.umd.min.js @@ -3,4 +3,4 @@ * https://github.com/zack24q/vue-navigation * Released under the MIT License. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueNavigation=t()}(this,function(){"use strict";function e(){return"xxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function t(e,t){return(e.name||e.path)+"?"+e.query[t]}function n(e,t){return Array.isArray(e)?e.indexOf(t)>-1:"string"==typeof e?e.split(",").indexOf(t)>-1:!!isRegExp(e)&&e.test(t)}function o(e,t){if(e===t)return!0;var n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;var r=!0,i=!1,a=void 0;try{for(var c,u=n[Symbol.iterator]();!(r=(c=u.next()).done);r=!0){var s=c.value;if(e[s]!==t[s])return!1}}catch(e){i=!0,a=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw a}}return!0}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var i=[];window.sessionStorage.VUE_NAVIGATION&&(i=JSON.parse(window.sessionStorage.VUE_NAVIGATION));var a=i,c=function(e,n,o,r){n&&n.registerModule(o,{state:{routes:a},mutations:{"navigation/FORWARD":function(e,t){t.to,t.from;var n=t.name;e.routes.push(n)},"navigation/BACK":function(e,t){t.to,t.from;var n=t.count;e.routes.splice(e.routes.length-n,n)},"navigation/REPLACE":function(e,t){t.to,t.from;var n=t.name;e.routes.splice(a.length-1,1,n)},"navigation/REFRESH":function(e,t){t.to,t.from},"navigation/RESET":function(e){e.routes.splice(0,e.routes.length)}}});var i=function(t,r,i){var c={route:r},u={route:i},s=n?n.state[o].routes:a;u.name=s[s.length-1]||null,c.name=t,n?n.commit("navigation/FORWARD",{to:c,from:u,name:t}):s.push(t),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(s),e.$emit("forward",c,u)},c=function(t,r,i){var c={route:r},u={route:i},s=n?n.state[o].routes:a;u.name=s[s.length-1],c.name=s[s.length-1-t],n?n.commit("navigation/BACK",{to:c,from:u,count:t}):s.splice(a.length-t,t),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(s),e.$emit("back",c,u)},u=function(t,r,i){var c={route:r},u={route:i},s=n?n.state[o].routes:a;u.name=s[s.length-1]||null,c.name=t,n?n.commit("navigation/REPLACE",{to:c,from:u,name:t}):s.splice(a.length-1,1,t),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(s),e.$emit("replace",c,u)},s=function(t,r){var i={route:t},c={route:r},u=n?n.state[o].routes:a;i.name=c.name=u[u.length-1],n&&n.commit("navigation/REFRESH",{to:i,from:c}),e.$emit("refresh",i,c)};return{record:function(e,n,o){var f=t(e,r);if(o)u(f,e,n);else{var l=a.lastIndexOf(f);-1===l?i(f,e,n):l===a.length-1?s(e,n):c(a.length-1-l,e,n)}},reset:function(){n?n.commit("navigation/RESET"):a.splice(0,a.length),window.sessionStorage.VUE_NAVIGATION=JSON.stringify([]),e.$emit("reset")}}},u=function(e){return{name:"navigation",abstract:!0,props:{},data:function(){return{routes:a}},computed:{},watch:{routes:function(e){for(var t in this.cache)if(!n(e,t)){var o=this.cache[t];o&&o.componentInstance.$destroy(),delete this.cache[t]}}},created:function(){this.cache={}},destroyed:function(){for(var e in this.cache){var t=this.cache[e];t&&t.componentInstance.$destroy()}},render:function(){var n=this.$slots.default?this.$slots.default[0]:null;if(n){n.key=n.key||(n.isComment?"comment":n.tag);var o=t(this.$route,e);-1===n.key.indexOf(o)&&(n.key="__navigation-"+o+"-"+n.key),this.cache[o]?n.key===this.cache[o].key?n.componentInstance=this.cache[o].componentInstance:(this.cache[o].componentInstance.$destroy(),this.cache[o]=n):this.cache[o]=n,n.data.keepAlive=!0}return n}}},s=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},i=n.router,f=n.store,l=n.moduleName,h=void 0===l?"navigation":l,m=n.keyName,g=void 0===m?"VNK":m;if(i){var v=new t,p=c(v,f,h,g),d=i.replace.bind(i),y=!1;i.replace=function(e,t,n){y=!0,d(e,t,n)},i.beforeEach(function(t,n,i){if(t.query[g])i();else{var a=s({},t.query);t.path===n.path&&o(s({},t.query,r({},g,null)),s({},n.query,r({},g,null)))&&n.query[g]?a[g]=n.query[g]:a[g]=e(),i({path:t.path,query:a,replace:y||!n.query[g]})}}),i.afterEach(function(e,t){p.record(e,t,y),y=!1}),t.component("navigation",u(g)),t.navigation=t.prototype.$navigation={on:function(e,t){v.$on(e,t)},once:function(e,t){v.$once(e,t)},off:function(e,t){v.$off(e,t)},getRoutes:function(){return a.slice()},cleanRoutes:function(){return p.reset()}}}else console.error("vue-navigation need options: router")}}}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueNavigation=t()}(this,function(){"use strict";var e=[];window.sessionStorage.VUE_NAVIGATION&&(e=JSON.parse(window.sessionStorage.VUE_NAVIGATION));var x=e;function I(e,t){return(e.name||e.path)+"?"+e.query[t]}var g=function(N,A,E,w){A&&A.registerModule(E,{state:{routes:x},mutations:{"navigation/FORWARD":function(e,t){t.to,t.from;var n=t.name;e.routes.push(n)},"navigation/BACK":function(e,t){t.to,t.from;var n=t.count;e.routes.splice(e.routes.length-n,n)},"navigation/REPLACE":function(e,t){t.to,t.from;var n=t.name;e.routes.splice(x.length-1,1,n)},"navigation/REFRESH":function(e,t){t.to,t.from},"navigation/RESET":function(e){e.routes.splice(0,e.routes.length)}}});return{record:function(e,t,n){var o,r,i,a,s,c,u,f,l,h,m,g,v,d,p,y=I(e,w);if(n)g=y,v={route:e},d={route:t},p=A?A.state[E].routes:x,d.name=p[p.length-1]||null,v.name=g,A?A.commit("navigation/REPLACE",{to:v,from:d,name:g}):p.splice(x.length-1,1,g),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(p),N.$emit("replace",v,d);else{var O=x.lastIndexOf(y);-1===O?(f=y,l={route:e},h={route:t},m=A?A.state[E].routes:x,h.name=m[m.length-1]||null,l.name=f,A?A.commit("navigation/FORWARD",{to:l,from:h,name:f}):m.push(f),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(m),N.$emit("forward",l,h)):O===x.length-1?(s={route:e},c={route:t},u=A?A.state[E].routes:x,s.name=c.name=u[u.length-1],A&&A.commit("navigation/REFRESH",{to:s,from:c}),N.$emit("refresh",s,c)):(o=x.length-1-O,r={route:e},i={route:t},a=A?A.state[E].routes:x,i.name=a[a.length-1],r.name=a[a.length-1-o],A?A.commit("navigation/BACK",{to:r,from:i,count:o}):a.splice(x.length-o,o),window.sessionStorage.VUE_NAVIGATION=JSON.stringify(a),N.$emit("back",r,i))}},reset:function(){A?A.commit("navigation/RESET"):x.splice(0,x.length),window.sessionStorage.VUE_NAVIGATION=JSON.stringify([]),N.$emit("reset")}}},v=Object.assign||function(e){for(var t=1;t { +export default (keyName, noCacheList = []) => { return { name: 'navigation', abstract: true, @@ -52,7 +52,9 @@ export default (keyName) => { } } else { // cache new vnode - this.cache[key] = vnode + if (noCacheList.indexOf(this.$router.history.current.name) === -1) { + this.cache[key] = vnode + } } vnode.data.keepAlive = true } diff --git a/src/index.js b/src/index.js index 304cc81..d4c7d22 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ import NavComponent from './components/Navigation' import { genKey, isObjEqual } from './utils' export default { - install: (Vue, { router, store, moduleName = 'navigation', keyName = 'VNK' } = {}) => { + install: (Vue, { router, store, moduleName = 'navigation', keyName = 'VNK', noCacheList = [] } = {}) => { if (!router) { console.error('vue-navigation need options: router') return @@ -46,7 +46,7 @@ export default { replaceFlag = false }) - Vue.component('navigation', NavComponent(keyName)) + Vue.component('navigation', NavComponent(keyName, noCacheList)) Vue.navigation = Vue.prototype.$navigation = { on: (event, callback) => {