Have you heard of slots? That is what you need here. You could have slots for your thead and tbody, or you could even use scoped slots for each row iteration.
https://vuejs.org/v2/guide/components.html#Content-Distribution-with-Slots
Hello!
Before I start my project, I'm just playing around and work on pagination, deleting records stuff first and I found out that I will have repetitive code over and over for every models. I already done the mixins stuff and right now, it is working. My only problem is I want to make this like @extends on Laravel blade and just put like @yield, @section stuff like that for every component. I want to have a "master layout" for every component.
<template>
<div id="records-wrapper">
<div class="uk-alert" v-show="hasNoData">No books found.</div>
<div v-show="!hasData" uk-spinner></div>
<table class="uk-table uk-table-divider uk-inline" v-show="hasData">
<!-- DYNAMIC CONTENT-->
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th class="uk-text-capitalize">
<a href="#" uk-icon="more"></a>
<div uk-dropdown="mode: click; pos: bottom-right">
<ul class="uk-nav uk-dropdown-nav">
<li>
<a href="#" @click="confirmPurge" v-show="hasSelected">Remove marked items</a>
</li>
<li v-show="!hasSelected">No selected items</li>
</ul>
</div>
</th>
</tr>
</thead>
<tbody>
<tr v-for="item in items">
<td><input type="checkbox" class="uk-checkbox" v-model="selected" :value="item.id"></td>
<td>{{ item.id }}</td>
<td>{{ item.title }}</td>
<td>{{ item.description }}</td>
<td>
<a href="#" uk-icon="more"></a>
<div uk-dropdown="mode: click; pos: bottom-right">
<ul class="uk-nav uk-dropdown-nav">
<li><a href="#" @click="edit(item.id, 'books')">Edit</a></li>
<li><a href="#" @click="remove(item.id)">Remove</a></li>
</ul>
</div>
</td>
</tr>
<!-- END DYNAMIC CONTENT-->
</tbody>
<div v-show="loading" class="uk-overlay-default uk-position-cover">
<div class="uk-position-center">
<span uk-spinner></span>
</div>
</div>
</table>
<pager :dataSet="dataSet" @changed="fetch"></pager>
</div>
</template>
<script>
import DataViewer from "../mixins/DataViewer";
import Actions from "../mixins/Actions";
export default{
props: ['src', 'purgeUrl'],
mixins: [DataViewer, Actions],
created(){
this.fetch(1);
}
}
</script>
As you can see, all dynamic/changing content will just need to put inside comment to reduce code. How can I achieve that @section @yield like on Vue? Is this possible? I tried but that doesn't seem to solve what i'm trying to achieve.
I believe there's an alternative way of doing this using full SPA. But I prefer MPA right now.
Thanks.
As far as I know, there isn't similar functionality like you have in blades with vue. The closest you're going to get to that is doing an SPA, but even then it's just not the same. I'm like you and prefer an MPA, so that's something I would be interested in. You just need to be creative with how you structure and organize your components :)
Please or to participate in this conversation.