1

I have defined the following on my HTML:

<span v-if="valido" class="fas fa-check" style="position: absolute; right: 44px; top: 43px; color: green"></span>
<span v-else class="fas fa-exclamation-circle" style="position: absolute; right: 44px; top: 43px; color: red"></span>

Then I have this in my VM

data: {
    valido: false
}

And this function is being called when a input changes value

    validarRestricciones: function () {

        var empid = this.inputValue.substring(this.inputValue.indexOf('(') + 1, this.inputValue.length - 1);

        $.ajax({
            type: 'get',
            url: '/api/personas/validar?empid=' + empid,
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            statusCode: {
                200: function (data) {
                    this.valido = true;
                    return true;
                },
                412: function (data) {
                    this.valido = false;
                    return false;
                },
                500: function (data) {
                    return false;
                }
            }
        });
    }

Everything works fine and I can see in the console that valido changes from false to true but it does not change or redraw the spans that are attached to valido property. It seems that it is only done on the creation of the Vue component. How can I redraw that??.

NicoRiff
  • 4,803
  • 3
  • 25
  • 54

1 Answers1

3

Are you sure it's actually changing the value of "valido" you set in the data property? At the beginning of the function try setting "this" to a variable, like "let vm = this", and then within the inner functions where you change "valido" call "vm.valido = false" for example.

It's possible "this.valido" is being assigned to the status code function immediately surrounding it rather than the one set in the data variable.

Justin Feakes
  • 380
  • 1
  • 7