Skip to content

Commit 21cd51b

Browse files
authored
Merge pull request #2 from mrspartak/master
added watchers to change options reactively
2 parents 61860e2 + b540010 commit 21cd51b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

demo/VueRoughNotation.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@
9898
</div>
9999
</div>
100100

101+
<div class="section" style="background-color: #f5f5f5;">
102+
<div class="content">
103+
<h3>
104+
<RoughNotation
105+
:is-show="true"
106+
type="box"
107+
:color="colorChanging"
108+
:stroke-width="strokeWidthChanging"
109+
:padding="paddingChanging"
110+
>Reactive change</RoughNotation>
111+
</h3>
112+
<p>
113+
Color, Stroke width, Padding will change reactively
114+
</p>
115+
</div>
116+
</div>
117+
101118
<div class="content">
102119
<p>
103120
<a target="_blank" href="https://github.com/Leecason/vue-rough-notation/tree/master/demo">
@@ -109,6 +126,12 @@
109126
</template>
110127

111128
<script>
129+
Array.prototype.getNext = function () {
130+
let el = this.shift();
131+
this.push( el );
132+
return el;
133+
}
134+
112135
export default {
113136
name: 'VueRoughNotation',
114137
@@ -189,6 +212,20 @@ export default {
189212
],
190213
showGroup: false,
191214
showNoAnim: false,
215+
colorChanging: '#263238',
216+
strokeWidthChanging: 1,
217+
paddingChanging: 1
192218
}),
219+
220+
mounted() {
221+
let colors = ['#263238', '#b71c1c', '#4a148c', '#0d47a1', '#ffd54f', '#ffd54f', '#1b5e20', '#f57f17']
222+
setInterval(() => {
223+
this.colorChanging = colors.getNext()
224+
if(this.strokeWidthChanging > 6) this.strokeWidthChanging = 0
225+
this.strokeWidthChanging++
226+
if(this.paddingChanging > 9) this.paddingChanging = 0
227+
this.paddingChanging += 3
228+
}, 500)
229+
},
193230
};
194231
</script>

src/components/RoughNotation.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ export default (options) => ({
9494
this.hide();
9595
}
9696
}, { immediate: true });
97+
98+
this.$watch('color', (value) => {
99+
this.annotation.color = value
100+
});
101+
this.$watch('strokeWidth', (value) => {
102+
this.annotation.strokeWidth = value
103+
});
104+
this.$watch('padding', (value) => {
105+
this.annotation.padding = value
106+
});
97107
},
98108

99109
beforeDestroy () {

0 commit comments

Comments
 (0)