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:

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

Error message received from Express middleware: "Unable to modify headers after they have been sent."

I have created middleware for my Node Express app to perform the following tasks: Checking all incoming requests to determine if they are from a bot Allowing requests for raw resources to proceed Serving an HTML snapshot if the request is from a bot How ...

"JavaScript's versatility shines through with its ability to handle multiple variables

Presently, I am working with the following script: <v-tab :title="siteObject.xip_infos[index].lineid" > <div class="description text-left" :class="{ 'text-danger': item.status === 'DEACTIVE' }"> <small v-for="(f ...

The error message "React Native Redux useSelector is returning Undefined after navigation" has

After navigating to a new state, I am facing issues with accessing the updated state. Initially, I initialize my dataState in the reducer and update it using actions. On Screen 1, I successfully use this state after dispatching, but when moving to another ...

Converting text data into JSON format using JavaScript

When working with my application, I am loading text data from a text file: The contents of this txt file are as follows: console.log(myData): ### Comment 1 ## Comment two dataone=1 datatwo=2 ## Comment N dataThree=3 I am looking to convert this data to ...

JSON parsing error within the HTML Sidebar list

I have a JSON file that contains data I need to parse in order to display information in my sidebar. When a user clicks the button labeled "List all sessions", the goal is to showcase all of the available session details grouped by Session ID and location. ...

Error in PHP script when making an AJAX call

First of all, I want to thank you all for your help. The script is creating a table but sending empty information. I have tried to modify it like this: However, when I call the script, it gives me an error: So, I have edited the script code to clean it ...

Is it possible to send a request to a Spring Boot Admin server from a specialized interface?

As I endeavor to integrate a custom view featuring administrative utilities into Spring Boot Admin, I am faced with the challenge of invoking calls to the server. My plan involves implementing these endpoints within Springboot Admin and then accessing them ...

Customizing hyperlink styles with JavaScript on click

Hey there! I'm experimenting with something new. I've managed to change the background color of each link after it's clicked, but now I'm facing a challenge: How can I revert the original style when another link is clicked? Here's ...

Utilizing arrays in JavaScript alongside jQuery's methods such as $.inArray() and .splice()

I am currently dealing with an array that is limited to containing 12 values, ranging from 1 to 12. These values can be in any order within the array. My task is to iterate through the array and identify the first unused value, assigning it to a variable. ...

Tips for sending an ID to a path link in React Js

Can anyone assist me in setting up a path for a component like this "/products?id=uniqueId" in my React Js Project? The unique id is retrieved from the database and varies depending on the product chosen. Below is an excerpt of my code: CodeSandbox App.j ...

Repeated instances of the same name appearing in the dropdown list every time the tab button is clicked

When using my function in the onclick nav tabs event (triggered by clicking on any tab), I have a requirement where I need to ensure that no duplicate names are inserted into the dropdown list. The current function is working perfectly, but I am looking fo ...

Functional Components with Methods in ReactJS

When creating a functional stateless component that requires methods to access props, is there a recommended approach or best practice to follow? For instance: function Stateless(props) { function doSomething(props) { console.log(props); } ...

retrieve the source code from all .js links found within the document

There is a file labeled urls.txt. https://website.tld/static/main_01.js https://website.tld/static/main_02.js https://website.tld/static/main_03.js .... All the source code from every .js file in allsource.txt needs to be extracted. Instructions: To ge ...

methods to obfuscate a document while storing it in a different directory (vue.js)

I need assistance with obfuscating my server.js file and storing it in the dist directory within a subfolder named server. Currently, I am utilizing the CopyWebpackPlugin. new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static' ...

The functionality for tabbed content seems to be malfunctioning on Chrome and Firefox, however it works perfectly

In my index.js file, I have various functions set up like so: // a and b is placed at index.jsp $("#a").click(function (){ //this works on index.jsp and display.jsp(where the servlets forwards it). $("#b").load('servletA.html?action=dis ...

Access an attribute using slashes in Jquery

I've been struggling to use jQuery to select an object based on a unique filename attribute. However, I'm facing issues with escaping slashes when the selector is created using a variable. Despite spending hours trying different combinations, I s ...

Can someone assist me in understanding the proper syntax for the Node.js function that inserts a document into Watson's Discovery service from the watson-developer-cloud library?

I'm attempting to upload JSON documents into a Discovery collection using the Node.js watson-developer-cloud JDK. Here is the relevant code snippet: const DiscoveryV1 = require('watson-developer-cloud/discovery/v1'); const discovery = new D ...

SelectBoxIt jquery plugin can be applied after the completion of populating options in the select element with AngularJS

Utilizing AngularJS, I am dynamically populating a select box with the code below: <select ng-model="department" ng-options="dept as dept.name for dept in departmentList" class="fancy"> <option value="">-- select an optio ...

The AJAX email submission form is not functioning properly

Recently, I have upgraded my email sign-up form on the website to include validation. However, after adding the validation, the form no longer sends and an error message is not displayed. Upon inspecting, I found the following error: TypeError: null is ...

Connect the AngularJS data model with a Foundation checkbox element

I am attempting to link a model (a boolean value) to a checkbox created with Foundation (Zurb). I have created a small demonstration displaying the issue: http://jsfiddle.net/JmZes/53/ One approach could involve simply creating a function that triggers o ...