Svelte可写数组上的Uncaught ReferenceError



我得到一个未捕获的ReferenceError:$writableArray未在addFoo 中定义

array.js:

import {writable} from 'svelte/store'
export const writableArray = writable([])

stores.js:

import {writableArray} from './arrays.js'
import {subscribe} from 'svelte/internal'
import {writable} from 'svelte/store'
export const addFoo = (bar) => {
$writableArray = [...$writableArray, {
bar: bar,
datetime: Date.now()
}];
};
export const foos = addFoo() // this is so that I can have a readable store too

我的代码基于Svelte示例

不能在.js文件中使用$store语法。相反,使用正常的update功能:

writableArray.update(oldArray => [...oldArray, { newObject }])

最新更新