提问人:lache 提问时间:8/28/2023 更新时间:8/28/2023 访问量:24
在 svelte store 方法上触发组件函数
Trigger a component function on svelte store method
问:
我有一个苗条的商店,有一种叫做“正确”的方法。当 right 被触发时,我希望我的组件文件中的函数 handleNextImage 运行。我不确定如何正确地做到这一点,谢谢!
import { writable, get } from 'svelte/store';
const createMyStore = () => {
const store = writable({
Rows: [],
});
const { subscribe } = store;
return {
subscribe,
right: (cb: (msg) => void) =>
update((x) => {
....
return x;
}),
};
};
export const myStore = createMyStore();
元件。苗条
import { myStore } from '@screens/home/myStore';
myStore.right(() => {
console.log('go right in store');
handleNextImage()
});
const handleNextImage = () => {
does a thing...
};
答: 暂无答案
下一个:Julia 中函数参数的条件
评论
store.right()
handleNextImage()
right()
$: if ($myStore) handleNextImage()
$myStore
cb
right
right: (cb: (msg) => void) => update((x) => { cb('new x is '+x); return x; })