"Organizing Your Content: A Guide to Grouping Information under Specific

How can I organize content under different headings? I am using two methods to retrieve data:

1. axios.get('/api/get/headers')

2. axios.get('api/get/contents')

I am struggling with how to properly structure this, especially since the headers and corresponding content may vary.

Here is an example of a table setup:

<thead>
    <tr>
        <th v-for="header in headers" :data-key="header.name">{{ header.title }}</th>
    </tr>
</thead>
<tbody>
     <tr v-for="content in contents">
         <td :data-key="content.name"> {{content.title}}</td>
     </tr>
</tbody>

An additional challenge is that the content could be an array.

Answer №1

Here's a simple example showcasing the integration of axios with Vue.js to fetch and display content on a single page. Are you finding this helpful for getting started?

<html>
   <head>
      <script src="http://unpkg.com/vue"></script>
      <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
   </head>
   <body>
      <div id="app">
         <div class="header">{{headerText}}</div>
         <div class="content">{{contentText}}</div>
      </div>
   </body>
<script>
var vm = new Vue({
   el: "#app",
   data: function () {
      return {
         headerText: '',
         contentText: ''
      }
   },

   mounted: function () {
      axios.get("/api/get/headers").then(response => {
         this.headerText = response;
      })
      .catch(err => {
         console.log(err);
      });

      axios.get("/api/get/content").then(response => {
         this.contentText = response;
      })
      .catch(err => {
         console.log(err);
      });
   }
});
</script>

</html>

Update:

In your specific scenario, consider revisiting the list of headers to match name properties with content names before displaying the content. Look at this approach:

<thead>
    <tr>
        <th v-for="header in headers" :data-key="header.name">{{ header.title }}</th>
    </tr>
</thead>
<tbody>
     <tr v-for="header in headers">
         <td :data-key="header.name"> {{getContent(header.name).title}}</td>
     </tr>
</tbody>


<script>
...
    methods: {
        getContent(name) {
            for (var index in this.contents) {
                if (this.contents[index].name === name) {
                    return this.contents[index];
                }
            }
        }
    }
...
</script>

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

Utilize local .json data within a React component

Here is a snippet from my local .json file: { "results": [ { "id": 1, "title": "2 bedroom apartment to rent", "location": "30 South Colonnade London E14 5EZ", "description": "The building offers a communal lifestyle which co ...

Converting Plain JSON Objects into a Hierarchical Folder Structure using Logic

Looking at the data provided below: [ {name: 'SubFolder1', parent: 'Folder1'}, {name: 'SubFolder2', parent: 'SubFolder1'}, {name: 'SubFolder3', parent: 'SubFolder2'}, {name: 'Document ...

What is the best way to activate a JQ function with my submit button?

Is there a way to trigger a JQ function when clicking the submit button in a form? I managed to make Dreamweaver initiate an entire JS file, but not a particular function. ...

I am attempting to access an Angular variable using JavaScript, but unfortunately, I am encountering some issues

I'm currently implementing the following code: window.onload=function(){ var dom_el2 = document.querySelector('[ng-controller="myCtrl"]'); var ng_el2 = angular.element(dom_el2); var ng_el_scope2 = ng_el2.scope(); console.log ...

Transform text that represents a numerical value in any base into an actual number

Looking to convert a base36 string back to a double value. The original double is 0.3128540377812142. When converting it to base 36: (0.3128540377812142).toString(36); The results are : Chrome: 0.b9ginb6s73gd1bfel7npv0wwmi Firefox: 0.b9ginb6s73e Now, h ...

Access the 'from' path from Vue Router within a component

Is there a way to retrieve the previous route within a component without using router.beforeEach in router/index.js? I need to display different DOM elements depending on where the user navigated from to reach the current route. Although console.log(this ...

Eliminating the muted attribute does not result in the sound being restored

I am looking to implement a feature where a video loads automatically without sound, but when a user clicks a button labeled "Watch with Sound", the video restarts from the beginning and plays with sound. Below is the JavaScript code: let videoButton = do ...

Struggling to start the node express server running

I'm trying to set up a node server using express to run nodemailer. My frontend is built with create-react-app - I believe there should be no issues in that area. I have a few questions: Why isn't my express server functioning properly? Why do I ...

Running a React application through a personalized Express server, all the while ensuring seamless automatic updates throughout the development

I currently have a React application along with a completely distinct Express server application. To serve my React app using a customized express server, I utilize the following code within my Express app: app.get("*", (req, res) => { res. ...

Are computed properties in Vue.js automatically updated if they rely on methods?

Within my code, there exists a computed value known as today, which allows me to retrieve the current day, month, and year by utilizing the following code: today: function() { var currentDate = new Date(); return { day: currentDate.getDate(), ...

Display a dropdown menu when hovering over with a delay

I recently created a basic navigation menu with dropdown functionality using CSS3 initially, but I decided to enhance it by incorporating jQuery to display the dropdown after a set timeframe. However, I am facing an issue where all dropdowns appear when ho ...

Delete an item from an array based on its index within the props

I am attempting to remove a specific value by its index in the props array that was passed from another component. const updatedData = [...this.props.data].splice([...this.props.data].indexOf(oldData), 1); const {tableData, ...application} = oldData; this ...

Retrieve items from an array using indexes provided by a separate reference table

I am dealing with two different arrays. One array contains my data: var tab1 = ["one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"]; ...

Various methods for traversing through multidimensional arrays

When working with Cython, is there a way to create efficient general functions that can handle arrays of varying dimensions? For instance, consider the task of dealing with aliasing in functions: import numpy as np cimport numpy as np ctypedef np.uint8_t ...

What is the process for implementing an onAuthStateChanged function in Vue Native?

I am trying to achieve a similar functionality as shown below: export default class LoadingScreen extends React.Component { componentDidMount() { firebase.auth().onAuthStateChanged(user => { this.props.navigation.navigate(user ? 'App&ap ...

Looking for an instance of a node.js ftp server?

I'm facing a challenge in creating a node.js application that can establish a connection with an FTP server to download files from a specific directory: Despite attempting to follow the instructions provided in the documentation for the ftp npm packa ...

Exploring the inheritance of directives and controllers within AngularJS

I'm struggling to grasp the concept of inheriting a parent controller from a directive. In my setup, I have a simple example with a controller named MainCrtl. This controller is responsible for creating and removing an array of directives called inner ...

Encountering the 'error not defined' issue while attempting to generate a 404 error in a failed await call within the asyncData method of Nuxt.js

Just started working with Nuxt.js this evening and playing around with mock blog data. Encountered an issue related to non-existing data. Here's the asyncData method I am using when viewing a single blog post: async asyncData({ params }) { try { ...

Implementing Vuejs Array Push in Separate Components

I am attempting to extract data from an object and store it in an array using Vue. My goal is to have each value stored in a separate array every time I click on an item. Each click should push the todo into a different array. How can I achieve this separa ...

Incorporating CSS animations into Vue.js while an API call is being made

When a specific icon is clicked, an API call is triggered: <i class="fas fa-sync" @click.prevent="updateCart(item.id, item.amount)"></i> I am looking to add an animation to rotate the icon until the API call is complete or ...