Vue allows you to easily generate child div elements within a parent

Having some issues creating a child div with Vue. The code is being placed correctly, but it's being stored as an array.

<template>
    <div class="containers" v-bind:style="{ backgroundColor: pageStyle.backgroundColor, paddingLeft:'5%', paddingRight:'5%',}">
        <div class="progress under_part">
            <div class="border_container">
              {{renderSeparator}}
            </div>
            <div class="progress-bar progress-bar-success" v-bind:style="{ width: this.progressBar }"></div>
        </div>
    </div>
</template>
<script>
computed:{
    renderSeparator: function() {
      const { page } = this.pageData;
      let totalPages = page.TOTAL_PAGES;
      let separator = [];
      for(var i = 1; i <= totalPages; i++) {
        separator.push('<div className="separator"></div>')
      }
      return separator;
    },
},
</script>

Answer №1

It seems like there might be a slight deviation in the approach you are taking to showcase the computed data. If you wish to persist with your current strategy, I suggest exploring the v-html directive.

Alternatively, here is an alternative suggestion:

new Vue({
  el: "#app",
  data: {
    pageData: {
      page: {
        TOTAL_PAGES: 5
      }
    }
  },
  computed: {
    renderSeparator () {
      const { page } = this.pageData;
      console.log(page)
      let totalPages = page.TOTAL_PAGES;
      let separator = [];
      for(var i = 1; i <= totalPages; i++) {
        separator.push(`Page ${i}`)
      }
      return separator;
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <div class="containers">
    <div class="progress under_part">
      <div class="border_container">
      
        <template v-for="separator in renderSeparator">
          <div class="separator">{{ separator }}</div>
        </template>
        
      </div>
      <div class="progress-bar progress-bar-success" v-bind:style="{ width: this.progressBar }">      </div>
    </div>
  </div>
</div>

If there's any confusion or queries, feel free to reach out.

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

Eliminating an element from an array based on a single criterion

Here's a question that might seem simple to some: Let's say I have an array like this... var array = [ {id: 1, item: "something", description: "something something"}, {id: 2, item: "something else", description: "something different" ...

How to retrieve JSON data from unidentified objects using JQuery

I have made an AJAX call and received a JSON file as the response: [ { "LINKNAME": "Annual Training", "HITS": 1 }, { "LINKNAME": "In Focus Newsletter", "HITS": 1 }, { "LINKNAME": "NITA (secured)" ...

Maintain the proportion of the browser window when reducing its size

<html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <img src="spacer--1200x800.png" width="1200" height="800" /> </body> </html> This section contains CSS ...

Exploring the iteration process of a JavaScript array with Node-API

Currently, I am in the process of developing a Node.js addon utilizing Node-API. My algorithm takes a Javascript array as input, processes it within the addon, and then returns the result. For implementing any logic on the array, I need to iterate through ...

Challenges with Websocket connectivity following AKS upgrade to version 1.25/1.26

We currently have a Vue.js application running on AKS with no issues on version 1.23, although some webpack/websocket errors are showing up in the console. However, after upgrading our AKS Cluster to either version 1.25 or 1.26, even though the pods are a ...

Why is the 3rd argument necessary when using useReducer?

According to the information provided in the documentation: [init, the 3d argument] allows you to separate the logic for determining the initial state outside of the reducer. This is particularly useful for resetting the state later in response to an ac ...

Angular filter is causing an error message saying "Unable to interpolate," but the filter is functioning as expected

I have implemented the filter below (which I found on StackOverflow) that works perfectly fine on one page. However, when using the same object, it throws an error as shown below: app.filter('dateFormat', function dateFormat($filter){ return f ...

Let the Vuejs transition occur exclusively during the opening of a slide

Trying to implement a smooth transition when the toggle button is clicked. Successfully applied the transition effect on the slider, but struggling to animate the text inside the div.hello class upon sliding open. <transition name="slide"> <a ...

Is it necessary to include the jQuery-Do alert command before using console.log() in JavaScript or jQuery code?

const firstResponse = ""; $.get("firstCall.html", function (response) { processResponse(response); }); function processResponse(content) { firstResponse = content; } const secondResponse = ""; $.get("seco ...

Is it possible to retrieve HTML content using YQL?

Imagine the scenario where you need to retrieve information from a web page structured like this: <table> <tr> <td><a href="Link 1">Column 1 Text</a></td> <td>Column 2 Text</td> <td>Colum ...

The request does not include the cookies

My ReactJS client sends a cookie using this NodeJS code snippet: res.cookie("token", jwtCreation, { maxAge: 24 * 60 * 60 * 1000, // Milliseconds (24 hours) sameSite: 'None', // Cross-site requests allowed for modern browser ...

AngularJS does not run the code inside the ref once directive

Code within the block of this.verifyUserToken does not execute. It appears that the issue may stem from asynchronous calls, as the data returned is not yet available. I am unsure of how to proceed in handling this. this.verifyUserToken = function(){ ...

Code snippet: Retrieve the previous and upcoming events based on the current date from an array (JavaScript/Angular)

Is there anyone who can assist me with an algorithm? I have a list of events and need to retrieve the next event and previous events based on the current date. For example: I fetch all events from an SQL database like so: events = [ {eventId:1, event ...

Utilizing JavaScript and Node to create a multidimensional array of objects across multiple datasets

I'm facing an issue with this problem. Are there any differences between the arrays in the examples below? Here's one in React: const multiDataSet = [ { columns: [ {title: "Last name", width: {wpx: 150}} ...

Creating unique appbars for different sections on my sidebar in ReactJs

I am trying to implement a responsive drawer and AppBar using material-ui (@material-ui/core). My goal is to display a specific AppBar for each section of the drawer. For instance, when the user navigates to the Timetable section, I want the AppBar label t ...

Merge arrays with identical names within the same object into one cohesive object containing all elements

I just started using Vue and I'm not entirely sure if it's possible to achieve what I have in mind. Here is the structure I have: { "items":[ { "total":1287, "currency":"USD", "name":"string", "itemID":"", "pro ...

Click to remove the accordion div

My query is regarding an accordion feature that I have implemented. <div id="accordion" class="accord"> <h2> <a href="#">Item1</a></h2> <div> Content1 </div> <h2 > &l ...

Generic partial application fails type checking when passing a varargs function argument

Here is a combinator I've developed that converts a function with multiple arguments into one that can be partially applied: type Tuple = any[]; const partial = <A extends Tuple, B extends Tuple, C> (f: (...args: (A & B)[]) => C, ...a ...

Processing requests through Axios and Express using the methods GET, POST, PUT, and DELETE

When working with express router and Axios (as well as many other frameworks/APIs), the use of GET/POST/PUT/DELETE methods is common. Why are these methods specified, and what are their differences? I understand that a GET request is used to retrieve dat ...

Troubleshooting a JQuery AJAX Autocomplete problem involving PHP and MySQL

I am facing an issue with my autocomplete feature. It is functioning properly on one of my pages, but not on this particular page. Even though the correct number of entries is being retrieved, they all appear to be "blank" or are displayed in black text th ...