Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
data() variable refuses to update when set inside nested functions

I am very new to VUE so please forgive if my terminology is not correct.

I am trying to set a variable which is defined in the script tag "data()" function.

I am trying to set a new value for a variable defined in data() from inside the "created()" lifecycle event. This works fine if done at the root level, but i need to do it within 2 nested calls as shown below and it will not work when nested inside the function calls:

app.vue

<template>
  
  <div class="container">
  
    <Button @btn-click="providerPicked" id="current-provider" :text="'Current Provider: ' + currentProvider" />


  </div>  
 
</template>


<script>
import { ZOHO } from "./assets/ZohoEmbededAppSDK.min.js";
import Button from './components/Button'

export default {
  name: 'App',
  components: {
    Button,
  },
  data() {
    return{
      currentProvider: 'x'
    }
  },
  created() {
    console.log("CREATED HOOK")
    ZOHO.embeddedApp.on("PageLoad",function(data)
      {
        console.log(data);
        //Custom Business logic goes here
        let entity = data.Entity;
        let recordID = data.EntityId[0];

      ZOHO.CRM.API.getRecord({Entity:entity,RecordID:recordID})
        .then(function(data){
          console.log(data.data[0])
          console.log(data.data[0].name)
            //THIS DOES NOT WORK - variable still comes back 'x' in template, notice this is nested twice.
            this.currentProvider = data.data[0].name;
        });

      });
      
      ZOHO.embeddedApp.init();

      //THIS DOES WORK - SETS VAR TO "reee" in template, notice this is not nested
      this.currentProvider = "reee"
      
     
  }
  
}
</script>



about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use arrow functions instead of anonymous functions.

Arrow functions do not bind this, and thus this will refer to the outer scope.

created() {
  console.log("CREATED HOOK")
  ZOHO.embeddedApp.on("PageLoad", (data) => {
    console.log(data);
    //Custom Business logic goes here
    let entity = data.Entity;
    let recordID = data.EntityId[0];

    ZOHO.CRM.API.getRecord({ Entity: entity, RecordID: recordID })
      .then((data) => {
        console.log(data.data[0])
        console.log(data.data[0].name)
        //THIS DOES NOT WORK - variable still comes back 'x' in template, notice this is nested twice.
        this.currentProvider = data.data[0].name;
      });

  });

  ZOHO.embeddedApp.init();

  //THIS DOES WORK - SETS VAR TO "reee" in template, notice this is not nested
  this.currentProvider = "reee"
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda