Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add examples for JSON string for inline props #1882

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/content/3.guide/1.writing/3.mdc.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ defineProps(['type'])
::
::

Multiple props can be separated with a space:

```md
::alert{type="warning" icon="exclamation-circle"}
Oops! An error occurred
::
```

If you want to pass arrays or objects as props to components you can pass them as JSON string and prefix the prop key with a colon to automatically decode the JSON string.
Note that in this case you should use single quotes for the value string so you can use double quotes to pass a valid JSON string:

::code-group

```md [array.md]
::dropdown{:items='["Nuxt", "Vue", "React"]'}
::
```

```md [number-array.md]
::dropdown{:items=[1,2,3.5]}
farnabaz marked this conversation as resolved.
Show resolved Hide resolved
farnabaz marked this conversation as resolved.
Show resolved Hide resolved
::
```

```md [object.md]
::chart{:options='{"responsive": true, "scales": {"y": {"beginAtZero": true}}}'}
::
```
::

Note that an array with numbers is also accepted without enquoting it with single quotes (see `number-array.md` example).
farnabaz marked this conversation as resolved.
Show resolved Hide resolved

### YAML method

The YAML method uses the `---` identifier to declare one prop per line, that can be useful for readability.
Expand Down