Skip to content

Commit ff54d68

Browse files
authored
docs: document data (#1416)
1 parent c979087 commit ff54d68

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/api/options.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ These options will be merged with the component's existing options when mounted
1010
:::
1111

1212
- [`context`](#context)
13+
- [`data`](#data)
1314
- [`slots`](#slots)
1415
- [`scopedSlots`](#scopedslots)
1516
- [`stubs`](#stubs)
@@ -44,6 +45,43 @@ const wrapper = mount(Component, {
4445
expect(wrapper.is(Component)).toBe(true)
4546
```
4647

48+
## data
49+
50+
- type: `Function`
51+
52+
Passes data to a component. It will merge with the existing `data` function.
53+
54+
Example:
55+
56+
```js
57+
const Component = {
58+
template: `
59+
<div>
60+
<span id="foo">{{ foo }}</span>
61+
<span id="bar">{{ bar }}</span>
62+
</div>
63+
`,
64+
65+
data() {
66+
return {
67+
foo: 'foo',
68+
bar: 'bar'
69+
}
70+
}
71+
}
72+
73+
const wrapper = mount(Component, {
74+
data() {
75+
return {
76+
bar: 'my-override'
77+
}
78+
}
79+
})
80+
81+
wrapper.find('#foo').text() // 'foo'
82+
wrapper.find('#bar').text() // 'my-override'
83+
```
84+
4785
## slots
4886

4987
- type: `{ [name: string]: Array<Component>|Component|string }`

0 commit comments

Comments
 (0)