Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  57] [ 4]  / answers: 1 / hits: 18338  / 7 Years ago, fri, march 24, 2017, 12:00:00

I'm passing an array of image filepaths to a component.
I'm wondering what would be the best way to watch a prop change in Vue.js component, if I pass a different array?



I'm using bootstrap carousel, so wanna reset it to first image when array changes.
In order for simplicity I reduced code example to this:



Vue.component('my-images', {
props: ['images'],

template: `
<section>
<div v-for=(image, index) in images>
{{index}} - <img :src=image/>
</div>
</section>
`
});

More From » vue.js

 Answers
24
<template>
<div>
{{count}}</div>
</template>

<script>
export default {
name: 'test',
props: ['count'],
watch: {
'$props':{
handler: function (val, oldVal) {
console.log('watch', val)
},
deep: true
}
},
mounted() {
console.log(this.count)
}
}
</script>

[#58403] Wednesday, March 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;