autoChooseFirstQuestion.ts 783 B

1234567891011121314151617181920212223242526
  1. import { Question } from "@/types";
  2. import { store } from "../store";
  3. import { watch } from "vue";
  4. export function chooseQuestion(question: Question) {
  5. store.currentQuestion = question;
  6. }
  7. /** chooseQuestion 当currentTask改变是,自动选择第一题 */
  8. export function autoChooseFirstQuestion() {
  9. watch(
  10. () => store.currentTask,
  11. () => {
  12. // FIXME: 此时取到的还是score:null,但是 chooseQuestion之后就变成了score:0
  13. const firstQuestion = store.currentTask?.questionList[0];
  14. if (firstQuestion) {
  15. // const oldScore = firstQuestion.score;
  16. // console.log(oldScore);
  17. chooseQuestion(firstQuestion);
  18. // setTimeout(() => (firstQuestion.score = oldScore), 0);
  19. }
  20. }
  21. );
  22. return { chooseQuestion };
  23. }