0

Why when I insert objects into an array, they are inserted and overwritten in the first method

but in the second nothing happens?

    el:"#usersList",
        data () {
            return {
            users: []
            }
        },

This works

.then(response => (this.users = response.data))

Why this does not work?

    .then(
                function (response) {
                var arr = response.data;
                const rename = null;
                arr.forEach( function(data) {
                    switch(data["prava"]) {
                        case "1":
                          data["prava"] = "User 0";
                          break;
                        case "2":
                            data["prava"] = "User 1";
                          break;
                        case "3":
                            data["prava"] = "Mod";
                            break;
                        case "4":
                            data["prava"] = "Admin";
                            break;
                        case "5":
                            data["prava"] = "Owner";
                            break;
                        default:
                            data["prava"] = "User 1";
                      }
                  });
                this.users = arr;
            })
1

1 Answer 1

1

the component instance this is not available inside then callback but if you use the arrow function it can be available :

.then((response)=>{
            var arr = response.data;
            const rename = null
            ...
           this.users = arr;
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.