1

I'm working on a multipage application using Vue, and in my project I have a directory called "pages" which contains subdirectories for each page. The subdirectories contain their own App.vue and main.js, like so:

src
|
+--pages
  |
  +--Home
  |  |
  |  +-- App.vue
  |  +-- main.js
  |
  +--About/
  |  |
  |  +-- App.vue
  |  +-- main.js
  |
  +--base.vue

I'm coming from Django-land, where can I have a template that houses most of the style information, headers, etc., and I can reuse the template across pages and inject content, and I'm trying to do the same here. I have most of my website in base.vue, and I want to be able to render different content as provided by the other pages.

For example:

base.vue

<template>
<div>
  Header text.
  <div id="body">
  </div>
</div>
</template>

<style>
@import '../assets/style.css';
</style>

<script>
...
</script>

And Home/App.vue

<template>
<div id="app">
  <div id="body"> <-- replace for this in base.vue, and use the styles defined in base.vue.
  New content
  </div>
</div>
</template>

<style>
</style>

<script>
...
</script>

So the page would essentially look like this:

Header text.
New content

How would I go about this using Vue?

1 Answer 1

1

You need 'slot templates' for this:

https://v2.vuejs.org/v2/guide/components-slots.html

https://alligator.io/vuejs/component-slots/

Thank you!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.