Guide to incorporating a Vuejs dashboard template into your Laravel 5.7 project

After diligently following the CoreUI documentation guidelines for integrating in vuejs development, I have discovered specific components designed for use within a vuejs environment. The documentation outlines the necessary installation commands which I executed as follows:

git clone https://github.com/coreui/free-bootstrap-admin-template.git my-project
$ cd my-project
$ npm install.

Upon completion, I transferred the files from the /src folder to the /resources directory of my Laravel project, adding the following lines of code:

mix.js('resources/js/app.js', 'public/js')
.js('resources/js/bootstrap.js', 'public/js')
  /*This is the mainjs on template /src*/
.js('resources/js/main.js', 'public/js') /*This line is added*/
   .sass('resources/sass/app.scss', 'public/css');

mix.browserSync({
       proxy: 'http://localhost:8000'
   });

To compile the code in the /main.js file, which executes template dependencies for webpack

Upon running “npm run watch”, an error occurred:

ERROR in ./resources/js/router/index.js
Module build failed: SyntaxError: Unexpected token (68:31)

  66 | 
  67 | // Views
> 68 | const Dashboard        = () => import('@/views/Dashboard')
     |                                ^
  69 | 
  70 | const Colors           = () => import('@/views/theme/Colors')
  71 | const Typography       = () => import('@/views/theme/Typography')

I then modified the lines containing

const Dashboard        = () => import('@/views/Dashboard')

and replaced them with

import Dashboard        from 'resources/js/views/Dashboard.vue'

This adjustment resulted in another error:

ERROR in ./resources/js/router/index.js
Module build failed: SyntaxError: Unexpected token (64:31)

  62 | 
  63 | Containers
> 64 | const DefaultContainer = () => import('resources/js/views/Dashboard.vue')
     |                                ^
  65 | 
  66 | 
  67 | // // Views

Finding documentation on implementing VueJS templates into Laravel projects proves challenging, making the integration of these templates complex. If you have any suggestions or solutions regarding this matter, please feel free to comment below.

Answer №1

If you're having trouble with imports in your Laravel-based Vue project, consider trying this solution:

const Dashboard = () => System.import('@/views/Dashboard');

I personally found that using System alongside import fixed the issue for me. Another tip is to set up:

const import = System.import();

At the beginning of your router file to streamline all your imports.

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

Changing input values in Javascript without overwriting existing values can be achieved using various

Looking to modify an input value without using the element.value property. The goal is to edit the value without replacing the entire string in the element. For instance, we want to remove the first character from the input field: this.value.substring(1) ...

Exploring the Various Path Options in Angular 2 Routing

As a newcomer to Angular and Node JS, I am currently working on an application and struggling with how to efficiently navigate between my different components. Users can input the name of a user and add books associated with them When clicking on a book ...

Is there a way to retrieve the height of an image and adjust its parent container height to be automatic?

Is there a way to achieve the following using pure JavaScript instead of jQuery? I want to find the height of an image within a figure element and if the image's height is less than 200 pixels, I need to set its container's (parent's) heigh ...

Create a function that allows users to toggle and display only one div within a group at a time using

The following code successfully toggles individual divs, but it displays active divs in a stack when toggling. I am trying to achieve the functionality of "showing only one at a time". Any suggestions? function toggle_visibility(id) { var e = document ...

Having trouble accessing state data in Pinia using the Setup function

I'm currently diving into the Composition API and Pinia with Vue3. While trying to fetch data from the store, I encountered an issue. When I add response data to the character state in the fetchCharacterById action, it appears to be empty when I chec ...

Iterating over each element within an array using the map method

I am facing an issue while trying to map values to a new array. The challenge lies in the fact that the property I am mapping can either be a number or an array. When it comes to arrays, I encounter a problem as my result ends up being an associative arra ...

"Learn the art of combining an ajax request with a captivating background animation at the same time

I'm currently working with the following code snippet: $('#contentSites').fadeOut(200, function() { // Animation complete $.get("my_account_content.php?q=" + content, function(data){ $("div#contentSit ...

Adding numerous items to a blank array in React following receiving a response from an API in React

When I upload 4 images, I receive 4 different URLs one by one. I need to save each URL in a separate object. const [imageURLs, setImageURLs] = useState([]) const handleImageUpload = async(e) => { const files = e.target.files for (let i = 0; i &l ...

Endless asynchronous loops with setInterval()

My nodejs application requires multiple infinite loops that call asynchronous functions. I was contemplating the following approach: async function process1() { ...perform some asynchronous tasks... } async function process2() { ...perform some as ...

Is there a way to automatically recalculate the "Total Price" when the input values are adjusted?

Whenever I add an item to the cart, it gets appended to the row in the shopping cart, and the price adjusts accordingly. However, I'm having trouble getting the price to adjust whenever I change the input values (input type: "number"). I can't se ...

What is the best method for invoking ajax requests from a service in AngularJS?

I am working on an Employee controller that includes properties such as Id, Name, and Specification. I have created an Employee service which makes an ajax call to retrieve a list of employees. However, every time I make the call, I receive an empty resp ...

Executing untrusted JavaScript code on a server using a secure sandbox environment

I am facing difficulties in creating a secure node sandbox that can execute untrusted code while allowing users to communicate with the program through api calls (input and output). My goal is to establish a browser console where users can run their own se ...

How to efficiently import an external ES module from a URL using TypeScript

I've recently started experimenting with Observable notebooks and I must say, it's been a great experience so far. Now, my next goal is to integrate a notebook into my web app. The following vanilla JavaScript code using JavaScript modules accomp ...

Ways to Access Python List in JavaScript within a Django Template

I am currently working in oTree, a Django based environment for social experiments. I have encountered an issue while attempting to import lists from Python into an HTML template for use in Javascript. Although I can successfully display the lists in HTML ...

The datepickers in jQuery are failing to initialize every time the modal is opened

I have encountered an issue with using modals in my web application to receive user input. The problem arises when a user opens multiple modals one after another - the jQuery datepickers fail to initialize properly for the second modal onwards. It seems th ...

Angular 2: Executing a function after ngFor has completed

Within Angular 1, I crafted a personalized directive called "repeater-ready" to pair with ng-repeat for triggering a callback method upon completion of an iteration: if ($scope.$last === true) { $timeout(() => { $scope.$parent.$parent.$ ...

Is it possible to utilize TypeScript code to dynamically update the JSON filter with variable values?

I am dealing with a JSON filter in which the value for firmwareversion needs to be replaced with a dynamic value. Here's how I've set it up: //JSON filter this.comX200FilterValue = '{ "deviceType": "ComX", "firmwareV ...

How can one check in JavaScript if a specific URL was targeted with a XMLHttpRequest?

While I am familiar with monitoring network traffic in the browser's development tools and having XMLHttpRequests shown in the console, I am curious if there is a specific window property that showcases all network activity at once? ...

How to load several Collada objects in THREE.js

When loading multiple car models using a loop in THREE.js, I've encountered an issue where sometimes all objects load correctly, but other times not all of them load. For instance, if the loop iterates 3 times, it may only load 2 objects at times, whi ...

When the menu is selected, I would like for this div to both appear on the screen and slide

I need this div to be visible and move up when a menu item is selected. Can anyone provide a solution for this? Thank you in advance. <html><head> <script type="text/javascript"> <!-- var divobject = null; function init(id){ div ...