Create a Vue component within the same component itself

Seeking help with a puzzling issue that has left me stumped. Currently, I am facing a problem.

In my project, there is a component called SelectForm.vue (which includes form buttons). My goal is to have another instance of SelectForm appear below the original one when a button is clicked within the SelectForm.vue component. Is this achievable?

Answer №1

Develop a container component that displays multiple instances of SelectForm components. Upon clicking the button on the first form, trigger an event using emit, listen for it within the container, and generate a new form.

Vue.component('Wrapper', {
    template: `<div>
        <SelectForm v-for="(form, index) in numForms" @new="numForms++" />
    </div>`,
    data() {
        return {
            numForms: 1
        }
    }
})

Vue.component('SelectForm', {
    template: `<div>
        The Form<br />
        <button @click="$emit('new')">Duplicate</button>
    </div>`
});

new Vue({
    el: "#app"
})

Check out this fiddle for reference

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

What is the process for including a custom Jasmine matcher definition in Typescript?

I've been searching around for information on creating custom Jasmine matchers using TypeScript and it seems like a common issue. However, none of the solutions I've come across have worked for me. My setup includes: { "typescript": "2.3.2", ...

Uncharted Territory: Exploring asynchronous loops with async await and Promise.race?

Currently, I am involved in a project that requires brute forcing a PDF password. To achieve this task, I am using PDF.js to verify the password and implementing promise.race to execute parallel functions for efficient performance. This is how I have str ...

Determining the dimensions of a div once it has completed loading

Is there a way to retrieve the width and height of a div after it has fully loaded, rather than before? I am currently using JavaScript to get the dimensions, but it seems to be returning the values before the image has finished loading. How can I rectify ...

Exploring the Implementation of FormulateInput for 'select' Type Using v-for in Vue.js

I have a form with two select inputs, where the options in the second input depend on the selection made in the first one. The first select is called "Area" and its options are fetched dynamically from the server. The second select, named "City", displays ...

The header and sub-navigation are in disarray and require some help

Dear web experts, After six months of learning to code websites, I'm tackling a big project with some challenges. The recent changes to the header and subnav have thrown everything off balance, making it look wonky and not quite right. Specifically, ...

Using the IE method getelementbyid to target an object within the document

Is there a way to use getElementById to access an object that already exists in the document? I am specifically trying to target the element "test" which is nested within parentDiv1. While this code works in Firefox, it's not functioning properly ...

Is it possible to have one table nested inside another?

Is there a plugin available that allows me to create a table inside another table, linked by an ID and expandable? Something similar to the example shown in this image. Alternatively, is it possible to generate this automatically using a JavaScript functi ...

What steps can be taken to customize this code in order to develop a dictation application?

Currently, I have a code that functions by comparing two strings: str2 (which represents user input) and str1 (our reference string). The purpose is to determine whether any words in str2 are spelled correctly or incorrectly. So far, the code works well. H ...

Adjust the dimensions of an image post-creation

let displayedImage = Ti.UI.createImageView({ image : somefile.png, height:'100', width:'100' }); The code above shows how I created the image. But now, I am wondering how I can resize the image after its initial creation. ...

"Encountered an issue while attempting to send the message: Unable to retrieve data" while utilizing NextJS and the

Currently, I am utilizing fetch along with NextJS to attempt to send information such as name, phone number, email, company, and message to an API. However, I am encountering an issue where the error message simply states 'Failed to fetch' in the ...

End the SQL connection in Nodejs

I'm having trouble closing the connection for a query using connection.close(). Does anyone know how to properly close the connection inside a route file? var express = require('express'); var router = express.Router(); var connection = req ...

What could be causing the issues with my scroll function?

Can anybody help me figure out why my code isn't functioning as expected? I've tried various troubleshooting methods but still can't pinpoint the problem. $(document).ready(function () { function load_arrow { $('.fa.fa-caret-squar ...

Implementing server-side caching with axios: a step-by-step guide

Presently, I am in the process of developing an application that integrates a Laravel API with a Vue.js frontend. To handle caching in the API, I have implemented the spatie/laravel-responsecache package. When I directly access a specific URL, such as htt ...

Ways to adjust the width of b-table th

How can I adjust the width of the th to expand the rows of the table like in the screenshot? Is there a way to add a class to th? View what I want here logTableField: [ { key: "LogDate", label: "Tarih",thClass: 'bg-white tex ...

What is the best way to relay error messages to other sections of the form?

I am currently tackling a challenge with Vue and Laravel. The issue at hand involves an error class that I have created for a form which interacts with 3 different components. For instance, there is the base form component and then a child component of th ...

Properly managing mouseover events on a flipped div: tips and tricks

I created a div that flips when clicked using some HTML and CSS code. It works perfectly in Firefox 39 and Chrome 43. Here is the markup: <div class="flip-wrapper flippable-wrapper" id="fliptest-01"> <div class="flip-wrapper flippable ...

Ways to display tab information from a related component

Hello all, I am new to Vue.js and I am facing an issue with showing tab data from a sibling component. I have included my code below. Can someone please assist me with this problem? Although I am able to toggle the tabs, I am unable to display the data fr ...

Replicating row with distinct values

I'm experiencing some difficulties with a particular issue. I currently have two tables as shown below: <table id="customFields1" class="table table-bordered table-hover additionalMargin alignment"> <thead> <tr> < ...

Ways to switch between Vue components

My main App.vue file contains elements like the navigation bar, with the rest of the content rendered by vue-router. I'm attempting to add a series of modals to this file so that they can be accessed from any route when clicking on the corresponding l ...

Optimizing Node.js public js files based on different environments: A complete guide

Is there a way to customize public JavaScript files for different environments? Specifically, I want to change the socket.io connection location: For development: var socket = io.connect('http://localhost/chat'); For production: var socket = ...