Vue JS causing page to flash briefly before disappearing

I recently started exploring Vue and I'm working on creating a basic search function that takes a user input query and displays all matching users.

To help me with this, I've been following a video tutorial for guidance.

Despite not encountering any errors in my console, I'm facing a peculiar issue where the page content briefly loads, then suddenly flashes white and goes completely blank.

The code snippet for the page is as follows:

<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
        <div class="container" id="searchPage">
            ...
        </div>

        ...

        <script src="assets/app.js"></script>

    </body>
</html>

In addition, here is my app.js script:

Vue.http.headers.common['X-CSRF-TOKEN'] = document.getElementById('X-CSRF-TOKEN').getAttribute('content');

new Vue({

    el: '#searchPage',
    data: {

        query: '',
        users: [],

    },
    methods: {
        search: function() {
            this.$http.post('/', { query: this.query } ).then(function(response) {
                    console.log(response);
                }, function(response) {
                    // error callback
                });
        }
    }
});

What could be causing the sudden blank screen? Any insights would be greatly appreciated.

Answer №1

There are a few key points to note here. Firstly, it appears that you are using Vue 2.0. In Vue 2.0, the syntax v-on="submit:..."; is deprecated and resembles the older version 0.12. To prevent the form from submitting, you now need to include v-on:submit.prevent:

<!--This code snippet will prevent the form submission -->
<form class="form-horizontal" v-on:submit.prevent>

A similar issue arises with v-on="keyup: search", which should actually be written as v-on:keyup="search"

<!-- Execute the search method on keyup event -->
<input type="text" class="form-control" v-model="query" v-on:keyup="search">

I recommend referring to the official documentation at https://vuejs.org/guide/ to familiarize yourself with the updated 2.0 syntax.

Answer №2

A new perspective, a much easier solution. I've dedicated some time to resolving similar issues myself. As it turns out, the culprit was this:

https://i.sstatic.net/YLikG.png

Yes, in my coding error I used "=" instead of "==" in the second condition. In VB, this mistake wouldn't have caused any trouble...

Although I'm not entirely sure why this simple fix prevented the entire page from displaying with no errors in the console, I must admit that overall, I am quite enjoying using Vue JS (it has truly increased my productivity when creating client applications).

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

Encountering the error message "ws02 script tag does not define Map"

When I try to create a map using the following code: let myMap = new Map(); I encounter the error shown below. Script Error: The script engine encountered an error while executing the inlined Javascript function 'mediate'. com.sun.phobos.script. ...

Extending a universal design concept to a new theme within the MUI (Material UI) framework

I have implemented MUI's ThemeProvider and set up a Themes.js file. Within this file, I have defined the globalTheme for managing global styles such as typography and border-radius. My intention is to extend the properties of globalTheme to both light ...

leveraging axios to work with pagination data from Laravel array

Hey everyone, I could really use some help here. I'm feeling pretty stuck and frustrated because I can't seem to figure out what's wrong with my code. Let me provide more details. The snippet above is supposed to enable pagination from a Lar ...

MinifyJS - optimize all .js files within a directory

Seeking assistance to finalize my build process: I am currently transpiling es6 > es5 using babel. Once that is complete, I aim to minify all my .js files recursively with uglifyJS solely using NPM scripts (no grunt or gulp). My Requirements; Convert ...

Is it possible to generate a component dynamically using a string template?

I have a Component called "CDataTable" that renders columns in a for loop. Inside the loop, there is a template: <template v-if="typeof col.template !== 'undefined'" #body="{data}"> <component :is="compile(co ...

Why do certain servers encounter the "Uncaught SyntaxError: Unexpected token ILLEGAL" error when loading external resources like Google Analytics or fonts from fonts.com?

Working on a variety of servers, I encountered a common issue where some externally loaded resources would throw an error in Chrome: "Uncaught SyntaxError: Unexpected token ILLEGAL". While jQuery from the googleapis CDN loads without any problems, attempt ...

Troubleshooting: Problems with AngularJS $http.get functionality not functioning as expected

I have a user list that I need to display. Each user has unread messages and has not created a meal list yet. I want to make two http.get requests within the main http.get request to retrieve the necessary information, but I am facing an issue with asynchr ...

Webpack fails to handle CSS background images

I'm having trouble with my Webpack configuration as it's not processing CSS images set in the background property: background: url('./hero.jpg') no-repeat right; This is resulting in an error message that reads: ERROR in ./src/app/comp ...

Iterating through two classes in a Javascript loop

Hello, I'm facing a small obstacle that I'm hoping to overcome using JavaScript/jquery. Essentially, I have multiple div classes and I want to create a loop that adds a class to specific divs without manually assigning an id to each one. The goal ...

Angular - service workers leading to unsuccessful uploads

When uploading files using Uppy (XHRUpload) in my Angular 6 app, the process is smooth on localhost with the service worker disabled. However, enabling the service worker results in successful uploads only for small files, while larger files fail to upload ...

Having issues with 'direction' in React withStyles causing errors

I am experiencing an issue with my React website where I am using the withStyles feature to apply styles to a material-ui Grid element. Specifically, when attempting to use direction: "column" in the style, I encounter the error message provided below. Th ...

Arranging data in a table using PHP

After some thorough research, I am finally prepared to dive into the world of PHP. My project involves an HTML5 animation with table sorting functionalities - one button for sorting by date and another for sorting by title. Despite my efforts to find a cus ...

Activate video in Slick Slider with the click of a button

I am facing an issue with my slider setup, where each slide contains a video as the background along with play/pause buttons. When I try to play the video by clicking the corresponding button on a specific slide, I encounter this problem: if I click the pl ...

React TextField is not accommodating the new line character ' ' causing recognition issues

Explanation I have encountered an issue while using Material UI TextField and mapping through an array of objects fetched from a MongoDB database. Here is the code snippet in question: {state.map((item) => ( <TextField name=" ...

Creating customizable form fields based on user input in Laravel - here's how!

I am feeling a bit lost when trying to generate dynamic fields based on user input. For example, this field is where the user can enter how many fields they want to create: {!! Form::open(array('url' => 'home')) !!} <div clas ...

At times, an InvalidArgumentError occurs stating: "The 'handle' parameter must be a string."

I have incorporated 'React-google-login' into my React project and now I am working on an automated test to make sure it functions correctly. try { await driver.get("http://localhost:3000/"); await driver.wait(until.elementLocated(By.xpath(` ...

Fade out and slide close a div using jQuery

I am creating a new website and incorporating jQuery for animation and simplified JavaScript implementation. My goal is to have a button that, when clicked, will close a div with a fading out and slide up effect. Can this be achieved? Thank you. ...

"Real-time image upload progress bar feature using JavaScript, eliminating the need for

I have successfully implemented a JavaScript function that displays picture previews and uploads them automatically on the onchange event. Now, I am looking to add a progress bar to show the upload status. However, all the solutions I found online are rel ...

Is it possible to increment an integer value in jQuery after obtaining the sum result?

Actually, I'm trying to extract the integer value from my input field. For example, if I enter the value 4+5, I want to display the result as 9 in a separate div. However, instead of getting the expected result, I am receiving [object Object]. I&apo ...

When a panorama is entered in ThreeJS/Panolens, what is the orientation of the camera?

I want to use an equirectangular image with Panolens and achieve the same panorama viewer effect as seen in the links below: Even though Panolens.js is based on Three.js, I encounter a different result when I input my image compared to the first link abov ...