saberland/saber

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Can I inject posts into a Vue component (not layout)? #595

themindstorm posted onGitHub

I have a table of contents component which shows a list of posts. I tried this:

// components/toc.vue
<script>
export const data = {
  injectAllPosts: true
}
export default {
  props: ["page", ...],
  ...

When I check the Vue devtools, page does not have any property posts. Is there a way to do this?


You'd have to pass the page prop manually, like this:

// in your layout file:
<ComponentToc :page="page" />
posted by krmax44 almost 5 years ago

@krmax44 Thanks for the quick reply. Is there a chance that the ability to inject posts into components will be added soon?

posted by themindstorm almost 5 years ago

I don't really see a wide use-case for that. Components aren't meant to have page state, but to be page/layout-agnostic. A component usually is something like a button. If you want to create a post component used on the index page, category/tag pages etc. it is meant to be used like this:

<BlogPost :title="post.title" :createdAt="post.createdAt" />
<!--- or like this -->
<BlogPost :post="post" /> 

For page state, layouts are the intended way.

posted by krmax44 almost 5 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests