首页 > 解决方案 > 无法从可写 Svelte 存储中读取数据

问题描述

我无法从可写存储中读取所有数据:

Error: 'store' is not exported by src\stores.js, imported by src\components\Bar.svelte

Svelte 商店:

import {subscribe} from 'svelte/internal'
import {writable} from 'svelte/store'
export const barStore = (key, initial) => {
  const foo = localStorage.getItem(key)
  const data = foo ? JSON.parse(user) : initial
  const store = writable(data, () => {
    const unsubscribe = store.subscribe(value => {
      localStorage.setItem(key, JSON.stringify(value))
    })
    return unsubscribe
  })
  return store
}

风景:

<script>
  import {barStore} from '../stores.js'
</script>

<table>
  <thead></thead>
  <tbody>
    {#each $store as foo}
      <tr>
        <td>foo.bat</td>
        <td>foo.shit</td>
        <td>foo.crazy</td>
      </tr>
    {/each}
  </tbody>
</table>

标签: svelte-3

解决方案


推荐阅读