Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Possible to put component in array and render them?

I want to create a component and put that component in an array to render it later. I don't want to take the data from the component, pass it, then reconstruct it. Is this possible?

What I am trying to do is currently not working and gives the error:

The "data" option should be a function that returns a per-instance value in component definitions

I don't know if that is referring to this part of the code.

Code to create TodoItem component and add it to array:

addTodo() {
   if (!this.isTodoItemSet()) {
        this.throwError("You must input a todo!");
        return;
   }

   this.clearError();
      const todoItem = this.createTodoItem();
      this.addItem(todoItem);
   },

   createTodoItem() {
      const todoItem = <TodoItem id="this.newItemId" title="this.todoItem" />;
      this.newItemId += 1;
      return todoItem;
   },

   addItem(todoItem) {
      this.$props.todoItems.push(todoItem);
      console.log(this.$props.todoItems);
   },
...

Attempting to render the components from the array

<template lang="">
  <div>
    <li v-for="item in this.$props.todoItems" :key="item.id">
      <component v-bind:is="item"></component>
    </li>
  </div>
</template>
<script>
import TodoItem from "./TodoItem.vue";

export default {
  components: {
    TodoItem,
  },

  props: {
    todoItems: [],
  },
};
</script>
<style lang=""></style>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I just changed the createTodo function to this

createTodoItem() {
      const todoItem = Vue.extend(TodoItem);
      const todoItemInstance = new todoItem();
      todoItemInstance.id = this.newItemId;
      todoItemInstance.title = this.todoItem;
      this.newItemId += 1;
      return todoItemInstance;
    },
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!