From 55f21fc2085b305ca7c8c6e57e646c57f1d20fbf Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Sat, 25 Jan 2020 18:27:24 +1000 Subject: [PATCH] docs: document data --- docs/api/options.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/api/options.md b/docs/api/options.md index d385d3047..34f162755 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -10,6 +10,7 @@ These options will be merged with the component's existing options when mounted ::: - [`context`](#context) +- [`data`](#data) - [`slots`](#slots) - [`scopedSlots`](#scopedslots) - [`stubs`](#stubs) @@ -44,6 +45,43 @@ const wrapper = mount(Component, { expect(wrapper.is(Component)).toBe(true) ``` +## data + +- type: `Function` + +Passes data to a component. It will merge with the existing `data` function. + +Example: + +```js +const Component = { + template: ` +
+ {{ foo }} + {{ bar }} +
+ `, + + data() { + return { + foo: 'foo', + bar: 'bar' + } + } +} + +const wrapper = mount(Component, { + data() { + return { + bar: 'my-override' + } + } +}) + +wrapper.find('#foo').text() // 'foo' +wrapper.find('#bar').text() // 'my-override' +``` + ## slots - type: `{ [name: string]: Array|Component|string }`