Vue.js running locally does not trigger the ready function

When running the following code in jsfiddle, there are no issues. However, when attempting to run it on localhost, the ready function does not fire and the ordered list items are not displayed. How can this be resolved?

index.html

<body>
  <h3>Notícias</h3>
  <div id="app">
    <ol>
      <li v-for="noticia in noticias">
        <span>{{ noticia.id }}</span>
        <span>{{ noticia.titulo }}</span>
        <span>{{ noticia.data_inicio }}</span>
      </li>
    </ol>
  </div>
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <script src="app.js"></script>
</body>

app.js

var noticias = [
  {
    "id": 1,
    "titulo": "Lorem ipsum",
    "conteudo": "Lorem ipsum sit dolor amet",
    "data_inicio": "1990-12-06",
    "data_fim": "1990-12-07"
  },
  {
    "id": 2,
    "titulo": "Lorem ipsum sit",
    "conteudo": "Lorem ipsum sit dolor amet",
    "data_inicio": "1998-12-06",
    "data_fim": "1998-12-10"
  }
];

var app = new Vue({
    el: '#app',

    data: {
      noticias: []
    },

    ready: function() {
      this.$set('noticias', noticias);
    },

});

The files index.html and app.js are located in the same directory.

Answer №1

ready() is now outdated, for those using 2.x, it's recommended to use the mounted() function instead.

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

Inject the content loaded from the server into a div element, and insert that div at the

I am trying to insert the div(#loadmore) element inside the div(#boxchatting) element when the content from "result.php" is loaded into div(#boxchatting). Here is the code I used: $('#loadmore').prependTo('#boxchatting'); $('#boxc ...

Updating the Keycloak token in VueJS using keycloak-js even when it is still valid

I have implemented a VueJS frontend connected to Keycloak using keycloak-js openid, without using the implicit flow https://i.sstatic.net/BxhJh.png Currently, there is a scenario in which the Backend NodeJS adds groups to a user in Keycloak. However, in ...

Alter the Cascading Style Sheets (CSS) value by accessing a

I have two files, keyboard.css and keyboard.js. My objective is to modify a CSS rule: .ui-keyboard div { font-size: 1.1em; } Is there an alternative method to change the font size without utilizing $(".ui-keyboard div").css()? I want the modification ...

The addition of '?#' to the URL causes the page to be reloaded when Router.push is used

Upon clicking the sign-in button, this function activates and makes use of AWS Cognito: signIn() { let username = this.emailIn; let password = this.passwordIn; Auth.signIn(username, password) .then(user => { this.$router.push({ path: "d ...

Which delivers better performance: HTTP request from server or client?

Considering the optimal performance, is there a difference in using Angular's HTTP request within a MEAN-stack environment compared to utilizing Request.js or similar for server requests? ...

Running PHP using Node.js | Redirecting with the help of .htaccess

Currently, I am using a Node.js Server with the following configuration: app.use(express.static(__dirname + '/public')); However, I am facing an issue when trying to execute a php file using the XMLHttpRequest function like this: var xhttp = n ...

How can we use jQuery to hide a selected option from a dropdown menu and move it to another dropdown menu?

<select> <option value = "volvo" > Volvo < /option> <option value = "saab" > Saab < /option> <option value = "vw" > VW < /option> <option value = "audi"> Audi < /option> </select> ...

Implementing logic with multiple columns in JavaScript

Looking for a way to display an array of data in multiple columns using Java Script, like this: 1 2 3 4 5 6 7 8 9 instead of 1 4 7 2 5 8 3 6 9 Any suggestions would be greatly appreciated. Thank you. ...

Vue 3 – The <Transition> component displays a root node that is not an element and therefore cannot be animated

Within App.vue, there is a handy transition tag used to smoothly fade pages in and out. <router-view v-slot="{ Component }"> <transition name="fade" mode="out-in" appear> <component :is="Component& ...

Experiencing difficulties with using the javascript alternative to jQuery.ajax()

Here is a JavaScript Object: const data = { name: "John", age: 30, } const jsonData = JSON.stringify(data); The AJAX Request below successfully passes the data: $(function(){ $.ajax({ url:'two.php', ty ...

Implementing Batch File Uploads using Typescript

Is there a way to upload multiple files in TypeScript without using React or Angular, but by utilizing an interface and getter and setter in a class? So far I have this for single file upload: <input name="myfile" type="file" multi ...

Converting a Disable submit button from jQuery to alpinejs: A Step-by-Step Guide

Is there a way to convert the disabling of a submit button using jQuery to Alpine.js? The Code : <form> <input type="text" class="input-field" placeholder="Enter you name *" value="" /> <button ty ...

Activate Popover with Hover and simply click anywhere to dismiss

Currently utilizing Bootstrap 4 and intrigued by the popover feature that activates on hover and closes when clicked anywhere. I'm also interested in making links functional within the popover. Any suggestions or tips on how to achieve this? $(doc ...

Unravel JSON using JavaScript on the web

I encountered an issue while running this code and trying to decode it: var data = JSON.parse({"forms":[{"url":"example.com/example","name":"example"}]}) document.getElementById("name").innerHTML=data.forms.name Instead of the expected value, the returne ...

Avoid executing top-level path middleware with app.use('/') in Express routing when directly accessing child or nested paths

Perhaps the title may not be as accurate as I hoped, but I have a very simple example to share. On my website, there are two main areas - a public area and a restricted admin area. example.com/admin (admin home page) example.com/admin/news (news page) ...

The backbone view is having trouble processing the data from this.model.toJSON()

I've been working on a Backbone code implementation to display all modifications before adding data to my model. However, every time I try to add something from my form, my view returns "this.model.toJSON() is not a function" and I can't figure o ...

React with Redux throws an Invariant Violation error stating that it could not locate the "store" in either the context or props of the component "Connect(Body)"

I am attempting to link my component to a store utilizing the react + redux + react-redux + react-router approach. Despite encapsulating the parent with a store, I am encountering this error: [Invariant Violation: Could not find "store" in either the c ...

modify a column in a database table when a different field is chosen

I am working on a basic table with 4 columns, two of which are dropdown menus with the classes "ddm1" and "ddm2". Here is what I am trying to achieve: Users should not be able to select from "ddm2" until they have selected an option from "ddm1". When ...

Verify whether the labels are blank, remain as they are, or transfer the data to the database

Currently, I am utilizing PHP, HTML5, and JavaScript for my project. The task at hand involves creating a webpage that will be connected to a database. However, I have encountered an issue wherein the page proceeds to the next step and sends data even when ...

Setting the borderRadius for a web view on Android Maps V3: A complete guide

In my application, I am using Android Map V3 and have encountered a bug specific to the Kit-Kat version. The chromium kit throws up an error message - nativeOnDraw failed; clearing to background color, which prevents the map from being displayed. Despite ...