What are some strategies for leveraging various resources to create unique Vue layouts?

After extensively studying the relevant sections of the book Full-Stack Vue.js 2 and Laravel 5 and exploring various questions (such as vuejs application with different layouts (e.g. login layout, page layout, signup etc.)), I still find myself unable to solve this issue.

I have successfully developed a Laravel + Vue Single Page Application (SPA). However, when I attempted to create an administrator dashboard for this SPA with distinct JavaScript and CSS resources (to give it a completely different look and feel), I became quite confused. I am unsure about the proper algorithm to follow in order to accomplish this task.

You can get a general overview of the software structure below,

// app.js

require('./bootstrap');

import Vue from 'vue'
import App from './views/App'
import router from './router'
import store from './store'

// Layouts
import Default from './views/layouts/Default.vue'
import Dashboard from './views/layouts/Dashboard.vue'

Vue.component('default-layout', Default);
Vue.component('dashboard-layout', Dashboard);

Vue.config.productionTip = false

export default window.vue = new Vue({
    el: 'app',
    components: {
        App
    },
    router,
    store
});
// App.vue

<template>
    <div>
        <component :is="layout">
            <router-view/>
        </component>
    </div>
</template>
<script>
    import $ from 'jquery';
    window.$ = window.jQuery = $;

    const default_layout = 'default';

    export default {
        name: 'App',
        computed: {
            layout() {
                return (this.$route.meta.layout || default_layout) + '-layout';
            }
        },
    };

</script>
// Default Layout

<template>
    <div>
        <default-navigation :is-absolute="isAbsolute" />
        <slot/>
        <default-footer />
    </div>
</template>
<script>
    import DefaultNavigation from '../components/DefaultNavigation.vue';
    import DefaultFooter from '../components/DefaultFooter.vue';

    export default {
        name: 'Default',
        components: {
            DefaultNavigation,
            DefaultFooter,
        },
        computed: {
            isAbsolute() {
                if (this.$route.name == 'home') {
                    return true;
                }
            }
        },
    };

</script>
// Dashboard Layout

<template>
    <div>
        <!-- Nothing here yet. -->
    </div>
</template>
<script>
    import DHeader from '../components/Dashboard/Header.vue';
    import DSidebar from '../components/Dashboard/Sidebar.vue';
    import DTitle from '../components/Dashboard/Title.vue';

    export default {
        name: 'Dashboard',
        components: {
            DHeader,
            DSidebar,
            DTitle
        },
    };

</script>
// webpack.mix.js

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

mix.js('resources/js/dashboard.js', 'public/js')
    .sass('resources/sass/dashboard.scss', 'public/css');

How can I incorporate a completely different style file and additional JavaScript file into the dashboard layout?

Answer №1

If you're interested in having separate instances of Vue for each, here's how you can achieve that:

Start by creating distinct blade templates for both instances and set up individual routes for each template.

Route::get('/dashboard/{any?}', function () {
    return view('dashboard');
})->where('any', '[\/\w\.-]*');

Route::get('/{any?}', function () {
    return view('index');
})->where('any', '[\/\w\.-]*');

Next, create two separate Vue instances in different js files, such as app.js and dashboard.js. Consider storing them in a separate directory like dashboard/dashboard.js.

Remember to update your webpack.mix.js file accordingly:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

mix.js('resources/dashboard/dashboard.js', 'public/js')
    .sass('resources/sass/dashboard.scss', 'public/css');

Finally, make sure to connect the compiled files in the public directory with the respective blade templates.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain the value for every span class and insert the corresponding string into the input field

I have a series of tags labeled as 'tag-label' in spans. My goal is to combine the values of these tags and insert them into an input field, separating each value with commas. To demonstrate this, I've created a JSFiddle that showcases the ...

Unique Angular Circular Progress Bar SVG Interface Customization

The circular progress bar I have created was inspired by the angular-circular-progress repository on GitHub. This is my current progress input: https://i.sstatic.net/nDgfO.png I am looking to customize the end of the progress bar with a small CIRCLE and ...

Various colored backgrounds in a random arrangement on a grid post layout

I'm looking to implement this plugin for displaying blog posts, but instead of using an image as the background, my client wants different colored images. I have managed to figure out the code to achieve this based on a post I found here, but unfortun ...

Importing ES Module is a requirement when making updates to Angular framework

During the process of upgrading from Angular 6 to 8, I encountered a frustrating issue. Every time I attempt to run 'ng serve' or 'ng build', I encounter the following error: I have tried various solutions such as adding "type":"module ...

The reduce function does not pass the unit test

Here is a method that is part of an Angular component: public mapInvoices(invoices: any[]): Record<string, any> { return invoices.reduce((map, obj) => { map[obj.letterType] = obj; return map; }, {}); } During the unit test f ...

NodeJS can be used to calculate the number of days, weeks, and months between two specific dates. This can be

Working on developing a loan management system that utilizes NodeJS for the Back End and AngularJS for the front end. This is the plan in place: The system consists of 3 categories: Daily Loans Weekly Loans Monthly loans The loan amount is set at $5000 ...

Is there a way for me to extract text from a leaflet popup in order to generate the complete URL for an AJAX request?

When text within a popup is clicked, I want to trigger an ajax call. The content in the leaflet popup has been set previously by another ajax call. Below is the JavaScript code for both ajax calls: $("#button").click(function() { var name = document. ...

Even with React.memo(), functional components continue to trigger re-renders

I am facing an issue with my button component that contains a button inside it. The button has a state isActive and a click function passed to it. Upon clicking the button, the isActive flag changes, triggering the app to fetch data accordingly. However, t ...

Choosing a Date using a DateTimePicker

I recently implemented a directive in my HTML for selecting dates, and I'm struggling to add time slots to it. Here is the code snippet: JSFIDDLE angular .module('App',['ui.date']) .directive('customDatepicker', ...

Tips for handling alternate lines with two distinct styles in the Ace editor

I am looking to develop a unique note-taking editor using Ace. For instance, if I paste some Spanish text into the editor, I would like to add English words as notes for corresponding Spanish words. My goal is to display these English words above the resp ...

Changing a string to an integer within an array using JavaScript

I am working with an array displayed by console.log(temp) in the following format: temp = [{name: "Request A", data: "1"} {name: "Request B", data: "12"} {name: "Request C", data: "6"}] If I want to change the format of my array to look lik ...

Deciphering the Results of AngularJS

What sets 'template' apart from 'templateUrl' in AngularJS directive? index.html: <!DOCTYPE html> <html lang="en" ng-app="app"> <head> <meta charset="utf-8"> <title>Index</title> </he ...

Generating Smoke Effects with Three.js

I am looking to generate visually appealing brown smoke rising into the sky. Any tips on how I can achieve this effect? ...

What is the best way to make several revisions to a message on Discord?

Is there a way to edit the same message multiple times with a delay? Here is the approach I attempted: message.channel.send(`a`) .then(message => { setTimeout(() => { message.edit(`ab`) }, 1000); }) .then(message => { setT ...

Localhost is successful in running the API; however, deployment on the server is causing it

I have developed a website named example.com with two sections titled "service" and "ideas" that display dynamic data. This data is retrieved from and . Everything works fine when I test the project on localhost, but once I upload the React build folder ...

How can dependencies be conditionally imported in a module that is shared between React (Next.js) and React Native?

I am looking to create a shared Typescript module that can be used in both a React (Next.js) web app and React Native mobile apps. This module will be responsible for managing communication with the backend (Firebase) and handling state management using t ...

Turn off Satellizer Popup Window Title Bar

Currently, I am implementing the satellizer plugin for Facebook authentication. However, I have encountered an issue with the default popup login window of Facebook, which includes a title bar and menu options. I would like to transform this popup into a m ...

conceal a division beneath a YouTube video frame upon clicking

I need to hide the 'div .blind' element when a YouTube video (inside 'div #player') is clicked. How can I achieve this? Here's an example: JS: ... var player; function onYouTubeIframeAPIReady() { player = new YT.Player('pl ...

The absence of multiple lines on the x-axis in the linear chart was noticeable

Currently, I am facing an issue with loading a single axis line chart on my Dashboard.vue. The functionality involves users selecting a 'year' and a 'loan_type' from dropdown menus, after which the chart should display a 12-month record ...

Sending additional parameter to a return function callback

In my current project, I'm utilizing a library function that follows this structure: let arr = [1,2,3] arr.forEach((item, i) =>{ doSomething(inputParam, (err, result)=>{ ... //Use err and result }); }) The err and resu ...