Step 6 - gunjandatta/sp-dashboard-vue GitHub Wiki
This application will display a dashboard and an item form. We will configure these views with Vue components.
<template>
<div class="dashboard">
<div class="row">
<div class="col">
<Navigation />
</div>
</div>
<div class="row">
<div class="col">
<TableFilter />
</div>
</div>
<div class="row">
<div class="col">
<DataTable />
</div>
</div>
</div>
</template>
<script>
import DataTable from "../components/table.vue";
import TableFilter from "../components/filter.vue";
import Navigation from "../components/navigation.vue";
export default {
components: { DataTable, Navigation, TableFilter }
}
</script>We will create components for the dashboard, but implement them in a later step.
<template>
<div>
Navigation
</div>
</template>
<script>
export default {};
</script><template>
<div>
Filter
</div>
</template>
<script>
export default {};
</script><template>
<div>
Table
</div>
</template>
<script>
export default {};
</script><template>
<div>
<ItemForm />
</div>
</template>
<script>
import ItemForm from "../components/itemForm.vue";
export default {
components: { ItemForm }
};
</script><template>
<div>
<ItemForm :readOnly="true" />
</div>
</template>
<script>
import ItemForm from "../components/itemForm.vue";
export default {
components: { ItemForm }
};
</script>We will create components for the dashboard, but implement them in a later step.
<template>
<div>
Item Form
</div>
</template>
<script>
export default {};
</script>- Export a constant "Views" that can be referenced from the other components to change views
- Initialize the router
- Create a mapping for each view to a component.
import Vue from "vue";
import VueRouter from "vue-router";
import Dashboard from "./views/dashboard.vue"
import EditForm from "./views/editItem.vue";
import ViewForm from "./views/viewItem.vue";
// Available Views
export const Views = {
Home: () => { router.push("/"); },
CreateItem: () => { router.push({ name: "create" }); },
EditItem: (id) => { router.push({ name: "edit", params: { id } }); },
ViewItem: (id) => { router.push({ name: "view", params: { id } }); }
}
// Use the router
Vue.use(VueRouter);
// Create the router
const router = new VueRouter({
routes: [
{ name: "create", path: "/create", component: EditForm },
{ name: "edit", path: "/edit:id", component: EditForm },
{ name: "home", path: "/", component: Dashboard },
{ name: "view", path: "/view:id", component: ViewForm }
]
});
export default router;Now that the router has been defined, we need to reference it. Simply import it, and add it to the Vue initialization.
import Vue from "vue";
import App from "./app.vue";
import { Configuration } from "./cfg";
import router from "./router";
import Strings from "./strings";
// Create the global variable for this solution
window[Strings.GlobalVariable] = {
Configuration
}
// Render the app
new Vue({
router,
el: "#" + Strings.AppElementId,
render: h => h(App)
});The app template will need to be updated to render the router views.
<template>
<div class="bs">
<router-view></router-view>
</div>
</template>
<script>
export default {};
</script>