【发布时间】:2020-06-14 09:22:41
【问题描述】:
我想在一段时间后更改布尔值并继续重复该过程。然后我想将值单独传递给子组件。这里的 changeActive() 是改变 active 布尔值的函数。我想将值更改为第一个道具,然后在一段时间后第二个道具等等。
<template>
<div style="width:300px; margin: auto;">
<RatingLabel
:rating='rating[0]'
:active='active'
style="margin: auto;"
/>
<RatingLabel
:rating='rating[1]'
:active='active'
style="float: right;"
/>
<RatingLabel
:rating='rating[2]'
:active='active'
/>
<RatingLabel
:rating='rating[3]'
:active='active'
style="margin: auto;"
/>
</div>
</template>
<script>
import RatingLabel from '../atomic/RatingLabel'
import { mapState } from 'vuex'
export default {
components: {
RatingLabel,
},
data() {
return {
active: false,
}
},
methods: {
changeActive() {
setTimeout(function(){
this.active = !this.active;
console.log(this.active)
}, 3000);
}
},
mounted() {
this.changeActive()
},
computed: mapState(['rating'])
}
</script>
【问题讨论】: