简体   繁体   中英

svelte read nested store

In Svelte I can read from store using $ symbol:

<script>
  export let myStore;
</script>
<p>
  {$myStore}
</p>

How do I read from store that is a property of an object? Eg let's say foo.store is a store.

I have tried $foo.store , $(foo.store) and foo.$store , neither working!

I am aware I can do let foo_store = foo.store and then $foo_store , but I'm looking for a simpler way.

EDIT looking for solution for assignments to store too.

The short answer is that you can't — for the purposes of the syntactic sugar, stores are always free variables. For that reason it's common to use destructuring:

const { x, y, z } = stores;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM