0

soy nuevo en Vue y necesito hacer que funcione esto, el ejemplo es tomado de https://www.luisllamas.es/crear-un-interface-web-para-controlar-el-esp8266/ pero lo quiero adaptar para VUE Necesito ejecutar la función processReceived para actualizar GPIO

new Vue({
  el: '#app',
  data() {
    var jsonText = '{"command":"updateGPIO","id":D5,"status":"ON"}';
  },

  computed: {

    test() {
      processReceived(jsonText);
    },

  },
  methods: {
    processReceived: function (data) {
    var  json = JSON.parse(data);
      if (json.command == "updateGPIO") {
        updateGPIO(json.id, json.status);
      }
    },

    updateGPIO: function (id, status) {
      document.getElementById("input-label-" + id).textContent = status;

      if (status == "ON") {
        document.getElementById("input-label-" + id).classList.add("On-style");
        document
          .getElementById("input-label-" + id)
          .classList.remove("Off-style");
      } else {
        document.getElementById("input-label-" + id).classList.add("Off-style");
        document
          .getElementById("input-label-" + id)
          .classList.remove("On-style");
      }
    },
  },

})
3
  • ¿podrías explicarte mejor? el 8 oct. 2020 a las 21:58
  • Esta mal formulada esta pregunta. Especifica el problema o el error. el 27 mar. 2022 a las 16:31
  • La funcion computada debe devolver un valor. agregale return processReceived(jsonText); el 27 mar. 2022 a las 16:35

1 respuesta 1

0

para ejecutar la funcion processReceived() puedes colocar un boton dentro del div #app que lance dicha funcion:

<button @click="processReceived()">Ejecutar</button>

También podrías hacer que la función tome directamente los datos de data sin recibir parametros:

processReceived: function () {
    var  json = JSON.parse(this.jsonText);
      if (json.command == "updateGPIO") {
        updateGPIO(json.id, json.status);
      }
    }

Espero te sirva. Saludos.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.