From 9420e3613f0812436012f3f6bc659f3962be739e Mon Sep 17 00:00:00 2001 From: Nuintun Date: Fri, 20 Nov 2015 17:58:30 +0800 Subject: [PATCH] update files --- static/js/components/app-configure/index.js | 1 - static/js/components/directory/directory.html | 2 +- static/js/components/dynamic-item/index.js | 26 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/static/js/components/app-configure/index.js b/static/js/components/app-configure/index.js index 107d8f3..e066fa8 100644 --- a/static/js/components/app-configure/index.js +++ b/static/js/components/app-configure/index.js @@ -22,7 +22,6 @@ module.exports = Vue.component('app-configure', { return { name: '', path: '', - _cached: {}, submitError: '', popup: false } diff --git a/static/js/components/directory/directory.html b/static/js/components/directory/directory.html index a01466a..1801af1 100644 --- a/static/js/components/directory/directory.html +++ b/static/js/components/directory/directory.html @@ -1,3 +1,3 @@ -  +  \ No newline at end of file diff --git a/static/js/components/dynamic-item/index.js b/static/js/components/dynamic-item/index.js index 4c9d95e..2c92218 100644 --- a/static/js/components/dynamic-item/index.js +++ b/static/js/components/dynamic-item/index.js @@ -33,11 +33,21 @@ module.exports = Vue.component('dynamic-item', { return { name: '', value: '', - _cached: {}, nameError: '', valueError: '' }; }, + computed: { + uniqueCache: function (){ + var cache = {}; + + this.items.forEach(function (item){ + cache[item.name] = true; + }, this); + + return cache; + } + }, methods: { add: function (){ // trim value @@ -47,7 +57,7 @@ module.exports = Vue.component('dynamic-item', { // name error if (!this.name) { this.nameError = '不能为空'; - } else if (this.$data._cached[this.name]) { + } else if (this.uniqueCache[this.name]) { this.nameError = ' ' + this.name + ' 已存在'; } else { this.nameError = ''; @@ -61,9 +71,7 @@ module.exports = Vue.component('dynamic-item', { } // add item - if (this.name && this.value && !this.$data._cached[this.name]) { - // cache name - this.$data._cached[this.name] = true; + if (this.name && this.value && !this.uniqueCache[this.name]) { // add item this.items.push({ name: this.name, value: this.value }); @@ -76,10 +84,7 @@ module.exports = Vue.component('dynamic-item', { this[key] = ''; }, remove: function (index){ - var item = this.items[index]; - this.items.splice(index, 1); - delete this.$data._cached[item.name]; } }, events: { @@ -87,10 +92,5 @@ module.exports = Vue.component('dynamic-item', { this.nameError = ''; this.valueError = ''; } - }, - created: function (){ - this.items.forEach(function (item){ - this.$data._cached[item.name] = true; - }, this); } });