question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

How to pass props to component embedded in markdown?

See original GitHub issue

I have some Vue components inside my nuxt/content markdown:

hello.md:

== Title
<my-component :foo="bar"></my-component>
More text

How do I assign a value to ā€œbarā€? Itā€™s straightforward if bar is a constant, and thereā€™s also a method to create a variable in the frontmatter to pass to the component. What I canā€™t figure out is how to pass in a value from the outer component or page that contains the <nuxt-content> component.

Hereā€™s what doesnā€™t work:

  • Putting something in data() in the outer component
  • Adding a prop to <nuxt-content> itself: <nuxt-content :foo="bar">
  • Adding a property to the value that gets passed in :document
  • Trying to play games in the front matter

I think it might work to use a global variable, this.$foo="bar", but that is obviously bad practice.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
NozomuIkutacommented, May 6, 2021

@ccleve

You can pass props from outside NuxtContent component to components written in markdown files, in the 3rd way you described:

Adding a property to the value that gets passed in :document

Here is demo in CodeSandbox.

But, if you are talking about Nuxt Content Theme Doc, there is no way you extend page object fetched, except patching the package.

2reactions
ManasMadrechacommented, May 7, 2021

@NozomuIkuta Amazing šŸ˜„ This should be documented on the website.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass Markdown file as this.props in React?
I see. I'm using gulp, so first I'd need to write a gulp task that takes all the markdown files in the page...
Read more >
React Markdown: A Thorough Guide With Markdown Examples
Next, navigate inside the my-markdown-previewer: ... Then pass it as a children prop in the ReactMarkdown component like this:Ā ...
Read more >
Props - Nuxt Content
Pass props to your components in Markdown files using the {} MDC syntax.
Read more >
Markdown with Custom Components in NextJS | DevLog 007
I used react-markdown to render my markdown files in ReactJS. Each code block in each markdown file is injected into a code editor...
Read more >
How to embed React components in markdown using Gatsby ...
MDX is Markdown for the component era. It lets you combine JSX with Markdown's syntax. Yes, you can embed JSX code or even...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found