javascript - How can i bind string return from ajax call with v-html in v-for in vue.js? -
i want bind v-html string returning ajax call in v-for.
<div v-for="row in data"> <div v-html="gethtml[row.id]"></div>
//fun gethtml(i){ this.$http.get('.....').then((data) => return data.html;) }
it this:
@template
<div id="app"> <div v-html="newcontent"></div> </div>
@vue instance
var vm = new vue({ el: "#app" data: { newcontent: '' }, mounted: function() { var = this; this.$http.get(endpoint) .then(function(data) { that.newcontent = data }) .catch(function(error) { console.log(error); }); } });
what happening?
at example binding data property newcontent
div using v-html
directive. means everytime property changes div
content updated.
after component gets mounted
fire ajax request .then()
assign response data newcontent
property, seen before automatically update view due reactivity.
Comments
Post a Comment