【问题标题】:SvelteKit: Cannot reference store value inside <script context="module" />SvelteKit:无法在 <script context="module" /> 中引用存储值
【发布时间】:2022-04-06 19:15:35
【问题描述】:

SvelteKit / Svelte:无法从上下文模块中的“存储”获取或设置(读取或写入)值。

import {selectedStore} from "src/storelocation";

<script context="module">
  export const load = async ({params})=> {
    
     $selectedStore.value // throwing error
  }

【问题讨论】:

    标签: svelte sveltekit svelte-store


    【解决方案1】:
    import {selectedStore} from "src/storelocation";
    import { get } from 'svelte/store';
    
    <script context="module">
    export const load = async ({params})=> {
    
      // use this
     get(selectedStore).value;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 2023-02-18
      • 2023-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多