A
A
Artem892018-06-13 15:25:40
Vue.js
Artem89, 2018-06-13 15:25:40

How to update Vue component after receiving data from backend?

upd: Code https://jsfiddle.net/s7x9btm1/1/
I declare a component

new Vue({
  el: '#twofamain',
  data: {
  	twoFactory: false
  },

then in created I get data from the backend in which this variable is either true or false, in the same place this.twoFactory = obj.twoFactor and still in the template with v-show it is always false. Tried different hooks, still false. How to re-render a component after receiving data and update it to be reflected in v-show depending on true or false&

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danbka, 2018-06-13
@Artem89

Your this in success does not point to a Vue object. Do it like this:

created: function () {
        var vueObj = this;
  	$.ajax({	
  		url: "../php/getdashboard.php",
  		type: "POST",
  		data: {
  			emailLog:emailLog
  		},
  		success: function (res){
  			var obj = JSON.parse(res);
  			vueObj.twoFactory = Boolean(Number(obj.twofactorturn));
  		}
  	});
  },

I
Ignat Khaylov, 2018-06-13
@ignat_one

Make twoFactory a computed property .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question