从其他 .js 文件导入的非法重新分配

Illegal reassignment to import from other .js file

我想从另一个名为 'scores.js' 的文件导入分数变量,但是当 运行 Svelte 应用程序时它总是给我一个错误。

知道如何修复错误吗?

store.js

import { writable } from 'svelte/store'

export let score = writable(0)

Quiz.svelte

import { score } from './stores.js'

function getANewQuiz() {
    isModalOpen = false
    score = 0
    currentQuestion = 0
    quiz = getQuiz()
  }

错误

[!] Error: Illegal reassignment to import 'score'
src\Quiz.svelte (22:4)
20:   function getANewQuiz() {
21:     isModalOpen = false
22:     score = 0
        ^
23:     currentQuestion = 0
24:     quiz = getQuiz()
Error: Illegal reassignment to import 'score'

score 是一个商店,因此您可以在组件中使用 $score = 0(或 store.set(0))。

(Working example)