<template>
<span>{{time}}</span>
</template>
<script>
export default {
name: 'Timer',
data () {
return {
time: 0
}
},
mounted () {
setInterval(() => {
++this.time
}, 1000)
}
}
</script>
The main
<template>
<div class="tetris">
<timer></timer>
</div>
</template>
<script>
import Timer from './Timer'
export default {
name: 'Game',
components: {
Timer: Timer
},
}
In this context, what would be the optimal way to restart the timer from the parent component? Maybe passing a prop like "start", "stop", or "reset" without emitting events to prevent all instances of the timer from resetting simultaneously?