我有一个函数 changeActive 可以更改活动布尔值的值。但即使活动更改的值(我使用 console.log 检查)新值也不会在 v-bind:'active' 中传递给子组件。
<template>
<div style="width:300px; margin: auto;">
<RatingLabel
:rating='rating[0]'
:active='active'
style="margin: auto;"
/>
<RatingLabel
:rating='rating[1]'
style="float: right;"
/>
<RatingLabel
:rating='rating[2]'
/>
<RatingLabel
:rating='rating[3]'
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>