Configuring a Themeforest HTML template with Vue and Laravel. Issue encountered when attempting to load JS files using router.push

Currently working on my first frontend website using Vue and Laravel. I decided to purchase a template from Themeforest which is based on HTML/CSS/JavaScript.

The setup of Vue and Vue Router with Laravel is complete and everything seems to be functioning well. Here is how my app.js file looks:


    require('./bootstrap');
    import $ from 'jquery';

    window.Vue = require('vue');

    import VueRouter from 'vue-router';
    import routes from './router';
    import slider from "./components/slider/index.vue";
    import insideheader from "./components/slider/innerheader.vue";

    Vue.use(VueRouter);

    import App from './components/App.vue';
    Vue.component('slider', slider);
    Vue.component('insideheader', insideheader);

    const router = new VueRouter({
      mode: 'history',
      routes,
    });

    Vue.router = router;

    const app = new Vue({
        el: '#app',
        data: {
        },
        router: router,
        render: t => t(App),
     });

    require('./js/vendor/jquery-library.js')
    ...
  

This snippet showcases what my App.vue file consists of:


    import Home from "./../components/home.vue";
    import About from "./../components/about.vue";

    const router = [
      { path: '/', component: Home, name: 'home' },
      ...
    ]

    export default router;
  

If I directly navigate to '/home' or '/about' in the browser, everything displays properly. However, when using $router.push to load another Vue file dynamically, some CSS and JavaScript files are not rendering correctly without any errors logged in the console. It seems like the issue might be related to the JavaScript files as the page structure loads fine but the jQuery functions aren't executing as expected.

Any suggestions or assistance would be greatly appreciated.

Thank you in advance for your help!

Answer №1

One reason for this issue is the failure of jQuery to load...

In Vue Router, the page does not reload but rather the URL in the browser changes and the virtual DOM gets updated. As a result, the DOM is refreshed but jQuery functions are not executed.

While I may not be a Vue expert, it seems like moving the code below into a component and calling it in the home and about components or within the mounted function of these components could resolve the problem:

require('./js/vendor/jquery-library.js')
require('./js/vendor/jquery-2.2.4.min.js')
require('./js/vendor/bootstrap.min.js')
require('./js/owl.carousel.min.js')
require('./js/jquery.svgInject.js')
require('./js/isotope.pkgd.js')
require( './js/chartsloader.js')
require('./js/parallax.js')
require('./js/countTo.js')
window._ = require('./js/appear.js')
// require('./js/gmap3.js');
require('./js/main.js')

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

Issue encountered while upgrading @adonisjs/ally from version 2.1.3 to 4.1.3

Upon updating @adonisjs/ally from version 2.1.3 to 4.1.3, I encountered an error stating Cannot find module 'Model. To address this, I decided to comment out the AllyProvider line and try running it again. Although the error disappeared, I now face is ...

Is the height of $(element) equal to the clientHeight of the element?

Do these two elements have identical properties? In my experiments, it seems like they yield the same result. I'm currently working on enhancing my code by utilizing native JavaScript properties... ...

"Utilize Bootstrap Modal to load dynamic content with Ajax and incorporate loading

When I use the Bootstrap Modal to load content from another page, the data is quite complex with multiple queries and dynamic forms. As a result, when the modal opens, it tends to get stuck momentarily. I am looking for some sort of animation or indicator ...

Echo a JS variable into PHP and then insert a PHP file into an HTML element - a step-by-step guide!

Greetings to the wonderful community at stackoverflow, I am currently working on a variable code that allows for easy insertion of code from another file, such as a div. I am curious if it is possible to include a PHP file using JavaScript and JS variable ...

Guide on Implementing Right-to-Left (RTL) Support in Material UI React

Currently, I am in the process of developing an application designed for LTR usage, but I am interested in adding RTL support as well. The application itself is built on top of Material UI React. By using CSS Flex Box, I have managed to rotate the applicat ...

Utilizing Third-Party JavaScript Libraries in Typescript

After researching different Q/A threads, I found a method for incorporating external libraries in TypeScript. Following the recommendations, I successfully registered BT alert to an element using the following code snippet: import * as $ from "jquery"; im ...

Attempting to resolve the Bootstrap issue, currently in search of a suitable solution

Today I made the decision to utilize bootstrap to create a menu, but unfortunately, I've encountered a strange bug or conflict involving jQuery, potentially the UI, and Bootstrap. If you'd like, you can take a look at the picture provided in the ...

Ensuring User Authentication in Laravel 5.3

I am currently working with Laravel 5.3 and Valet. Within my web.php file: Auth::routes(); Route::group(['middleware' => 'auth'], function () { Route::get('/dashboard', 'DashboardController@index'); }); And i ...

Retrieve the class using a text string and then obtain the subsequent string

I am searching for the first class containing the text "Routed:" and then I want to retrieve the following string. I attempted to utilize document.querySelector, but I'm uncertain if this is the correct approach. <td class="msvb2">Routed:</t ...

Utilizing the no-data-text attribute in v-combobox with Vuetify: Tips and tricks

My application includes a simple combobox, and I am trying to set a default text message to display when there are no entries in the items props. To achieve this goal, I utilized the no-data-text prop by passing a specific variable to it. <v-combobox ...

What is the method for accessing State in a Class component using a concatenated String?

Looking to change up the typical method of using this.state, I am interested in utilizing a combined string instead. import React, { Component } from "react"; class Test extends Component { constructor(props) { super(props); this.sta ...

How to extract nested data in Vue.js using Laravel 6

There is a data for counter1 which contains cashier1 data as shown in the picture: Below is my Vue script: <script> const app = new Vue({ el:'#app', data:{ counter1:{}, }, mounted(){ ...

Ensure the initial word (or potentially all words) of a statement is in uppercase in Angular 2+

Struggling with capitalizing words in an Angular 2 template (referred to as view) led to an error in the console and the application failing to load, displaying a blank page: Error: Uncaught (in promise): Error: Template parse errors: The pipe 'c ...

Steps to dynamically update a button's href based on the active status of a class

I am facing a challenge in using Js and Jquery to dynamically change the href of a button based on the presence of a specific class. I am relatively new to Javascript and unsure if I am approaching this problem in the best way. Any suggestions on how to re ...

Dynamic anime-js hover animation flickering at high speeds

I have implemented the anime-js animation library to create an effect where a div grows when hovered over and shrinks when moving the mouse away. You can find the documentation for this library here: The animation works perfectly if you move slowly, allow ...

Please display the Bootstrap Modal first before continuing

Currently, I'm facing a challenge with my JS code as it seems to continue running before displaying my Bootstrap Modal. On this website, users are required to input information and upon pressing the Save button, a function called "passTimeToSpring()" ...

What is preventing TypeScript from recognizing enums in libraries?

Check out the TypeScript types defined for html-validator: declare namespace HtmlValidator { // ... enum ValidationResultsOutputFormats { json = 'json', html = 'html', xhtml = 'xhtml', ...

ui-grid-draggable-rows mistakenly identifies my data as a simple string

After successfully setting up the ui-grid-draggable-rows functionality by following the provided instructions, I encountered an error while running the code snippet from the example here. The error message I received is as follows: TypeError: this.spli ...

Navigating to two separate webpages concurrently in separate frames

I am working on creating a website with frames, where I want to set up a link that opens different pages in two separate frames. Essentially, when you click the link, one page (such as the home page in a .html file) will open in frame 1 on the left side, ...

What causes dates to shift by 24 hours?

I am facing an intriguing datetime dilemma. It seems like I just can't crack it and it's driving me crazy. Perhaps I overlooked something or didn't approach it in the right way. Currently, I am retrieving data from Mongo using Axios. The da ...