Skip to content

Commit 480f330

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [v28] one page modified
1 parent 97f2111 commit 480f330

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

views/vue.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,55 +133,68 @@ createApp(withOvermind(overmind, App)).mount('#app')
133133
{% endtab %}
134134
{% endtabs %}
135135

136-
### Reference specific state and actions
136+
### Accessing state in setup
137+
138+
You have to point to `.value` to access state from the hook with setup.
137139

138140
{% tabs %}
139141
{% tab title="components/SomeComponent.vue" %}
140142
```javascript
141-
<template>
142-
<div @click="actions.onClick">
143-
{{ state.foo }}
144-
</div>
145-
</template>
146143
<script>
147144
import { hooks } from '../overmind'
148145

149146
export default {
150147
setup() {
151-
const state = hooks.state(state => state.admin)
152-
const actions = hooks.actions(actions => actions.admin)
148+
const state = hooks.state()
149+
const actions = hooks.actions()
153150

154-
return { state, actions }
151+
return {
152+
foo: state.value.foo,
153+
actions
154+
}
155+
156+
// JSX
157+
return () => (
158+
<div onClick={actions.onClick}>{state.value.foo}</div>
159+
)
155160
}
156161
}
157162
</script>
158163
```
159164
{% endtab %}
160165
{% endtabs %}
161166

162-
### Using JSX
167+
### Scoped tracking
168+
169+
You can scope the tracking to specific state. In this example we only track changes to the properties accessed on the item within the template. Any changes to the items state itself does not affect this component, like adding/removing items.
163170

164171
{% tabs %}
165172
{% tab title="components/SomeComponent.vue" %}
166173
```javascript
174+
<template>
175+
<div @click="actions.onClick">
176+
{{ item.title }}
177+
</div>
178+
</template>
167179
<script>
168180
import { hooks } from '../overmind'
169181

170182
export default {
183+
props: ['id'],
171184
setup() {
172-
const state = hooks.state()
185+
const item = hooks.state(state => state.items[this.id])
173186
const actions = hooks.actions()
174187

175-
return () => (
176-
<div onClick={actions.onClick}>{state.value.foo}</div>
177-
)
188+
return { item, actions }
178189
}
179190
}
180191
</script>
181192
```
182193
{% endtab %}
183194
{% endtabs %}
184195

196+
###
197+
185198
## Plugin
186199

187200
Vue has a plugin system that allows us to expose Overmind to all components. This allows minimum configuration and you just use state etc. from any component.

0 commit comments

Comments
 (0)