Showing
2 changed files
with
14 additions
and
10 deletions
1 | <template> | 1 | <template> |
2 | - <AuthComponent :auth="isAuth" class="icon-btn" @click="onClick" :style="btnStyle"> | 2 | + <AuthComponent :auth="isAuth" class="icon-btn" :class="{'btn-selected': viewOption.selected}" @click="onClick" :style="btnStyle"> |
3 | <i class="iconfont" :class="iconClass" :style="iconStyle"></i> | 3 | <i class="iconfont" :class="iconClass" :style="iconStyle"></i> |
4 | <p v-if="viewText" class="icon-btn-text" :style="textStyle"> | 4 | <p v-if="viewText" class="icon-btn-text" :style="textStyle"> |
5 | <span class="view-text">{{Number(viewText) ? viewText : ''}}</span> | 5 | <span class="view-text">{{Number(viewText) ? viewText : ''}}</span> |
@@ -75,7 +75,6 @@ export default { | @@ -75,7 +75,6 @@ export default { | ||
75 | return { | 75 | return { |
76 | currentClass: {}, | 76 | currentClass: {}, |
77 | viewOption: {}, | 77 | viewOption: {}, |
78 | - btnSelected: false, | ||
79 | actionClass: '', | 78 | actionClass: '', |
80 | editText: null | 79 | editText: null |
81 | }; | 80 | }; |
@@ -102,7 +101,7 @@ export default { | @@ -102,7 +101,7 @@ export default { | ||
102 | btnStyle() { | 101 | btnStyle() { |
103 | let color = this.viewOption.color || defaultOption.color; | 102 | let color = this.viewOption.color || defaultOption.color; |
104 | 103 | ||
105 | - return `color: ${this.btnSelected ? (this.viewOption.selectedColor || color) : color};`; | 104 | + return `color: ${this.viewOption.selected ? (this.viewOption.selectedColor || color) : color};`; |
106 | }, | 105 | }, |
107 | iconClass() { | 106 | iconClass() { |
108 | if (this.actionClass) { | 107 | if (this.actionClass) { |
@@ -150,12 +149,12 @@ export default { | @@ -150,12 +149,12 @@ export default { | ||
150 | type() { | 149 | type() { |
151 | this.setCurrentClass(); | 150 | this.setCurrentClass(); |
152 | }, | 151 | }, |
153 | - option(val) { | ||
154 | - if (this.viewOption.selected !== this.option.selected) { | 152 | + option(val, oldVal) { |
153 | + if (oldVal.selected !== val.selected) { | ||
155 | this.actionClass = ''; | 154 | this.actionClass = ''; |
156 | } | 155 | } |
157 | 156 | ||
158 | - if (this.viewOption.iconBold !== this.option.iconBold) { | 157 | + if (oldVal.iconBold !== val.iconBold) { |
159 | this.setCurrentClass(); | 158 | this.setCurrentClass(); |
160 | } | 159 | } |
161 | 160 | ||
@@ -182,6 +181,7 @@ export default { | @@ -182,6 +181,7 @@ export default { | ||
182 | forEach(defaultOption, (value, key) => { | 181 | forEach(defaultOption, (value, key) => { |
183 | this.viewOption[key] = this.option.hasOwnProperty(key) ? this.option[key] : defaultOption[key]; | 182 | this.viewOption[key] = this.option.hasOwnProperty(key) ? this.option[key] : defaultOption[key]; |
184 | }); | 183 | }); |
184 | + | ||
185 | this.viewOption = {...this.viewOption}; | 185 | this.viewOption = {...this.viewOption}; |
186 | }, | 186 | }, |
187 | setCurrentClass() { | 187 | setCurrentClass() { |
@@ -197,15 +197,15 @@ export default { | @@ -197,15 +197,15 @@ export default { | ||
197 | this.currentClass = currentClass; | 197 | this.currentClass = currentClass; |
198 | }, | 198 | }, |
199 | changeBtnStatus() { | 199 | changeBtnStatus() { |
200 | - this.btnSelected = !this.btnSelected; | 200 | + this.viewOption.selected = !this.viewOption.selected; |
201 | 201 | ||
202 | if (this.viewOption.textAutoChange) { | 202 | if (this.viewOption.textAutoChange) { |
203 | if (!isNaN(Number(this.viewText))) { | 203 | if (!isNaN(Number(this.viewText))) { |
204 | - this.editText = Number(this.viewText) + (this.btnSelected ? 1 : -1); | 204 | + this.editText = Number(this.viewText) + (this.viewOption.selected ? 1 : -1); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | - this.actionClass = this.btnSelected ? currentClass.selected : currentClass.default; | 208 | + this.actionClass = this.viewOption.selected ? this.currentClass.selected : this.currentClass.default; |
209 | }, | 209 | }, |
210 | syncService(type, data) { | 210 | syncService(type, data) { |
211 | if (typeof this[type] === 'function') { | 211 | if (typeof this[type] === 'function') { |
@@ -248,7 +248,7 @@ export default { | @@ -248,7 +248,7 @@ export default { | ||
248 | this.syncService(this.syncFnName, { | 248 | this.syncService(this.syncFnName, { |
249 | articleId: this.articleId, | 249 | articleId: this.articleId, |
250 | commentId: this.commentId, | 250 | commentId: this.commentId, |
251 | - status: this.btnSelected | 251 | + status: this.viewOption.selected |
252 | }).then(backFn).catch(backFn); | 252 | }).then(backFn).catch(backFn); |
253 | } | 253 | } |
254 | } | 254 | } |
-
Please register or login to post a comment