How to watch prop change in Vue.js component?
<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>
You're good to go with this:
Vue.component('my-images', {
props: ['images'],
computed: {
imagesComputed: function () {
// just an example of processing `images` props
return this.images.filter((each, index) => index > 0);
}
},
template: `
<section>
<div v-for="(image, index) in imagesComputed">
{{index}} - <img :src="image"/>
</div>
</section>
`
});