我得到一个未捕获的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 }])