1

I am trying to add another user and I am experimenting with this code showed all around the internet.

So I tried this example below, it works fine, but how could I add another user, let's say for a guest?

is it possible? with like a conditional?

I am just trying to learn more about js and how I can solve this type of simple thing.

   methods: {
        login() {
            if(this.input.username == "admin1" && this.input.password == "pass1") {
                this.$store.commit("setAuthentication", true);
                this.$router.replace({ name: "secure" });
            } else {
                console.log("The username and / or password is incorrect");
            }
        }
    }
4

1 回答 1

1

You Can use Below Code:

 methods: {
        login() {
            if(this.input.username == "admin1" && this.input.password == "pass1") {
                this.$store.commit("setAuthentication", true);
                this.$router.replace({ name: "secure" });
            } else if (this.input.username == "guest" && this.input.password == "guest1") {
            //  block of code to be executed if the condition1 is false and condition2 is true
            }else {
                console.log("The username and / or password is incorrect");
            }
        }
    }
于 2021-09-30T04:30:33.153 回答