I am creating a SPA website with Vue.js. Well, I have a component such that:
Vue.component("locales",
{
props: ['productos'],
template:'<pre>{{productos}}</pre>',
data(){
listaLocales = this.productos;
}
}
);
This component is in a file called local.js
And in the HTML code I have this form that calls the method of a Vue instance:
<form class="form form--style" v-on:submit.prevent="buscar" action="/index.html">
<i class="fas fa-search"></i>
<input type="text" v-model="ciudad" placeholder="Lugares.." name="search" maxlength="50" id="ciudadBuscar">
<input type="submit" value="Buscar">
</form>
Well, that method that runs the form called "search" is this:
buscar(){
this.mostrarResultados();
},
mostrarResultados(){
this.locales = repo.peticionAjax('getLocales', saveData);
let localesHtml = $("<locales :productos=locales></locales>"); // es insertado en el HTML sin pasar por Vue.js
$("#cardTwo").html(localesHtml);
},
Show results correctly returns the data through an Ajax request with Axios. And by JQuery is inserted once having the data, a tag in HTML that refers to the Vue component. The problem is that when this tag is inserted by JQuery ( $("<locales :productos=locales></locales>"); y $("#cardTwo").html(localesHtml);
), it is literally inserted, without Vue rendering or evaluating the label itself and trying to find if the component exists.
The events in Vue do not seem to solve the problem, and I can not think of how to do it so that I can dynamically insert Vue components without the latter ignoring what I insert, not evaluating the tag and therefore not replacing the tag by its corresponding Template.