Just to start, I want to mention that there might be a more appropriate way to achieve what I'm trying to do. Essentially, I'm looking to dynamically add an instance of a Vue component when a user clicks a button to expand it. I came across this discussion on the vue.js forum for guidance. However, I'm encountering an issue where triggering the insert function through a button click isn't working as expected. The console error indicates "addNewStop is not defined at HTMLButtonElement.onclick".
The HTML structure in my template:
<div id="newCont"></div>
<button type="button" class="btn-primary" id="addStop" onclick="addNewStop()">Add Stop</button>
The script being called:
import Stops from '@/components/Stops'
const ComponentCtor = Vue.extend(Stops)
const componentInstance = new ComponentCtor({})
function addNewStop() {
componentInstance.$mount('#newCont')
}
I readily admit that I wasn't entirely sure about the correct approach initially and have found limited information on inserting new component instances. If there are alternative or better options out there that I should explore, I would appreciate any suggestions!
Edit:
The 'Stops' template actually consists of form inputs allowing users to specify delivery stops along a truck route. Below is its template structure:
<template>
<div class="stops">
<h4>Delivery</h4>
// Form fields for shipper name, location, date, time, etc.
</div>
</template>