Answer the question
In order to leave comments, you need to log in
VUE: how to correctly handle events when working with AXIOS and PHP?
Good evening.
Colleagues, help out! I've already broken my head! The task is banal: to pass a set of id (collected through Vue) to a regular php script that will make a selection from the mysql database and return the necessary field names.
To simplify understanding, I will simplify the example as much as possible:
We have the following query:
loadResult: function() {
axios({
method: 'post',
url: 'ses.php',
data: {
genset: JSON.stringify(this.genset)
}
})
.then(response=> {
this.resultBuyGenset = response.data;
})
}
echo "<div style=\"color: blue; cursor: pointer;\" v-on:click=\"testClick(777)\">Подгрузили!</div>";
Answer the question
In order to leave comments, you need to log in
Here is a snippet that essentially compiles the html with vue that came from the server.
Just like that, after the initialization of vue, it will not work.
/**
* Компонент который может скомпилить хтмл строку с кастом компонентами внутри
* <dynamic-html template="<div title='sdff' @click='alert(123)'/>" />
*/
export default {
functional: true,
props: {
template: String,
data: { type: Object, default: () => ({}) }
},
render(h, context) {
const template = context.props.template;
const dynComponent = {
template,
data() {
return context.props.data;
}
};
const component = template
? dynComponent
: {
template: `<div>Loading...</div>`
};
return h(component);
}
};
Use v-model="resultBuyGenset" as the v-on directive does not know how to wait for a promise response.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question