Сначала начните с v-if="canEdit"
на вашем <div>
. Затем в разделе сценариев компонента Vue мы создадим логическое значение canEdit
, а затем al oop для его регулярного обновления. Предполагается, что у вас есть определенный c Comment.vue
компонент, и this.comment
уже передан компоненту, может быть, в качестве опоры или чего-то еще, и что он содержит типичные Laravel поля модели, в частности created_at
.
data() {
return {
canEdit: true, // Defaults to `true`
checkTimer: null, // Set the value in `data` to help prevent a memory leak
createdAt: new Date(this.comment.created_at),
};
},
// When we first make the component, we set `this.createdPlus30`, then create the timer that checks it on a regular interval.
created() {
this.checkTimer = setInterval(() => {
this.canEdit = new Date() > new Date(this.created_at.getTime() + 30*60000);
}, 10000); // Checks every 10 seconds. Change to whatever you want
},
// This is a good practice whenever you create an interval timer, otherwise it can create a memory leak.
beforeDestroy() {
clearInterval(this.checkTimer);
},