Steps for loading data into a Vue.js application

I have created an app using the Vue CLI webpack and I am facing issues with loading data into a view. Below is the code in its current state:

main.js

// Setting up Vue imports
import Vue from 'vue'
import App from './App'
import router from './router'

// Importing Bootstrap for styling
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.config.productionTip = false
Vue.use(BootstrapVue)

/* Initializing Vue instance */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  data: {
    exchanges: [
      {name: 'gdax', price: 1450},
      {name: 'bitfinex', price: 1525}
    ]
  }
})

App.vue

<template>

  <div id="app" class="container">
    <h1>Arb Bot</h1>
    <router-view/>
  </div>
</template>

<script>
  export default {
    name: 'App'
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>

routes/index.js

// Setting up routes
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Opportunities from '@/components/Opportunities'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/opportunities',
      name: 'Opportunities',
      component: Opportunities
    }
  ]
})

Opportunities.vue

<template>
  <div>
    <h2>Bitcoin prices</h2>
    <table>
      <tr>
        <td>Exchange</td><td>Price</td>
      </tr>
      <tr v-for="exchange in exchanges" :key="exchange.name">
        <td>{{ exchange.name }}</td><td>{{ exchange.price }}</td>
      </tr>
    </table>
  </div>
</template>

The view is rendering properly but the data is not being loaded, hence the table rows are not visible in the browser.

How can I correctly load the data into the view and display the table?

Thank you

Answer №1

element: '#app',

This points to the element identified by ID=app, which appears to be absent in your situation.

To resolve this issue, assign the table with the ID of app:

<table id="app">

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: Unable to locate module: 'material-ui/Toolbar'

Encountering Error While Using Material UI Recently, I attempted to utilize the ToolBar and AppBar components of React Material UI. Unfortunately, I encountered an error message stating: "Module not found: Can't resolve 'material-ui/core/Toolbar ...

Is sending a stream to a variable the best option, or could there be another solution

Is there a way to pipe stream data to a variable? The writable stream examples mentioned in this documentation include: HTTP requests on the client side HTTP responses on the server side Zlib streams Crypto streams TCP sockets Child process stdin Process ...

Load data from a MySQL Database into a DataTable

I am currently in the process of developing a CRUD application. With a large dataset stored in a MySQL database, my intention is to utilize a JQuery DataTable instead of manually creating a table. However, the issue I am facing is that while the table appe ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Canvas featuring labels at the top with a strikethrough effect when utilizing a pie chart in chart.js

I am working on a piece of code that aims to showcase a summary of the most popular forms based on the number of inserted rows in their respective database tables. The goal is to visually represent this data using a pie chart generated with chart.js 2.8. & ...

Initiating automatic downloading through callback function in Internet Explorer

When attempting to initiate a download in IE within an angular+node configuration, I encounter a problem. Here is my current procedure: Users click on a download button The node server is requested to send a file The node server creates the file and sen ...

Ng-Repeat is generating empty list items

When I view this code in my browser, I see two list items, but there is no content displayed within them. The loop seems to be functioning correctly, but the items are not pulling any information from my list. I have revised my submission to accurately re ...

The functionality of selecting all items in v-select does not result in saving all of them

I'm currently working on integrating a select all button into the v-select component of Vuetify. The issue I am facing is that even though I can use the button to select all options, when I attempt to save, not all items are saved. However, if I manua ...

Is it possible to retrieve the controller path for an AJAX request from within a partial view?

Looking for a solution to fully decouple and reuse a partial view that allows users to select dates and filter results based on those dates. This widget can be used on multiple pages, so I wanted to add event listeners that would submit the form within the ...

Troubleshooting Issue: jQuery Popup Functionality Not Functional in ASP.NET Core 2.2

I'm having trouble with creating a popup form to add employees or categories. When I click the "Create" button, nothing happens. Take a look at my code: namespace EasyBay.Areas.Admin.Controllers { [Area("Admin")] public class CategoryControll ...

The functionality of Angular 2 md-radio buttons in reactive forms seems to be hindering the display of md-inputs

Currently, I am following the instructions for implementing reactive form radio buttons on a project using Angular 2.1.2 and Google's MD-alpha.10 Atom-typescript shows no errors in my code. However, when testing the application, I encountered the foll ...

Sort the alphabetically filtered list with "new" at the top

Currently, I am displaying a list of objects on my page and sorting them using the orderBy filter: orderBy:"name":false // each object also contains an id:number While this works well for the initial list, I am looking for a way to automatically display ...

How to extract a specific part of a string with regular expressions

I am currently working on a function to search for a specific substring within a given string. // the format is <stringIndex>~<value>|<stringIndex>~<value>|<stringIndex>~<value> var test = "1~abc1|2~def2|1~ghi3|4~jk-l4 ...

Is there a way to divide a string and insert something into the new array that is created?

I am facing an issue with adding a new fruit to a string that is converted into an array. Here's the scenario: var fruits = "banana,apple"; In an attempt to add a new fruit to this list, I tried converting it to an array and then using the push meth ...

Having trouble retrieving Bengali-language data from the server using jQuery AJAX

I am facing an issue where I am unable to fetch data in Bengali language from the server using ajax. Strangely, the data retrieved from the server is getting replaced by some unknown characters. However, if I directly retrieve the data without using ajax, ...

Implementing the expand and collapse functionality to the Discovery sidebar on the DSpace 4.2 xmlui platform

I recently began using DSpace and I am attempting to implement an expand/collapse feature in the Discovery sidebar of DSpace 4.2 xmlui using the Mirage theme. After finding some helpful jquery code, I attempted to add this functionality by placing the js f ...

Utilizing constants for DOM element objects across multiple methods in Vue.js

Is there a way to share DOM element objects between methods in Vue.js without duplicating code? I'm using @vue/cli and struggling to export them before the Vue.js code due to my limited experience with this framework. I have multiple nodes involved in ...

Choose a drop-down menu with a div element to be clicked on using Puppeteer

Issue Description: Currently encountering a problem with a dropdown created using material select. The dropdown is populated through an API, and when selected, ul > li's are also populated in the DOM. Approaches Tried: An attempt was made to res ...

Transferring the control's identifier to JavaScript using ScriptControlDescriptor

In my CreateChildControls() method, I am creating a control: HtmlGenericControl mycontrol= HtmlGenericControl("li"); mycontrol.ID = "controlID"; controlId = mycontrol.ID; protected virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors() { ...

What is the reason that this jQuery code is exclusive to Firefox?

I am currently working on a code snippet that enables users to navigate back and forth between images by displaying them in a lightbox at full size. The code functions flawlessly in Firefox, however, it does not seem to have any effect on IE, Chrome, and S ...