Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Seguimiento de la propiedad Class de mecanografiado en los componentes vuejs3

Estoy creando un juego web con mecanografiado en Vuejs3, pero me cuesta hacer que mis propiedades de clase de mecanografiado sean reactivas en mis componentes .vue.

He simplificado la clase para que quede más claro.

Juego.ts :

 import { Clock } from "@/modules/Clock"; export class Game { public clock: Clock; constructor() { this.clock = new Clock(60); } }

Reloj.ts :

 export class Clock { private _updateTimeRequest = 0; public initialTime: number; public timeLeft: number; constructor(startTime: number) { this.initialTime = startTime; this.timeLeft = startTime; this.start(); } private updateTime(): void { this.timeLeft--; if (this.timeLeft <= 0) { this.stop(); } } public start() { this.timeLeft = this.initialTime; this._updateTimeRequest = setInterval(this.updateTime.bind(this), 1000); } public stop() { clearInterval(this._updateTimeRequest); } }

GameView.vue :

 import GameClock from "@/components/GameClock.vue"; import { Game } from "@/modules/Game"; import { provide, ref } from "vue"; let game = ref(new Game()); provide("game", game); </script> <template> <div> <GameClock /> </div> </template> <style scoped></style>

GameClock.vue :

 <script setup lang="ts"> import { computed, inject } from "vue"; const game = inject("game"); const timeLeft = computed(() => { return game.value.clock.timeLeft; }); </script> <template> <div> <span>{{ timeLeft }}</span> </div> </template> <style scoped></style>

Entonces, la pregunta es, ¿cómo hago que mi propiedad timeLeft sea reactiva para que pueda mostrar la cuenta regresiva de la instancia de game.clock?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!