简体   繁体   English

复选框已选中,但我不想选中它

[英]Checkbox checked but I want it not checked

I have a issue where I don't know why I have that, so I want if the password is not correct with my prompt alert so with my v-model , the checkbox stays not checked but always it turns to checked, it doesn't do like I want and I can't explain that.... Here is my code :我有一个问题,我不知道为什么会有这个问题,所以我想如果我的提示警报密码不正确,所以使用我的v-model ,复选框保持未选中状态,但始终变为选中状态,它没有t 做我想要的,我无法解释......这是我的代码:

<template>
  <form  action="#/login" >
    <input type="email" placeholder="Insérez votre adresse-mail pour créer votre compte"/>
    <input type="password" placeholder="Mettez y votre mot de passe">
    <label for="admin"> Droits administrateurs </label>  <input type="checkbox" id="admin" v-model="checked" @click="noEntry">
  </form>
</template>

<script>
module.exports = {
  name: "Signup",
  data () {
    return {
      checked: false,
    }
  },
  methods : {
    noEntry()
    {let password;
      password = this.checked ? "" : prompt("Seul le personnel de la librairie y a accès, veuillez inscrire le mot de passe", "");
      if(password === "administrations") { this.checked = true;}
      else { this.checked = false}
    }
  }
}
</script>

<style scoped>

</style>

Thanks you everyone谢谢大家

Have a nice day祝你今天过得愉快

Please take a look at snippet:请看一下片段:

(use @change for checkbox and check if it is not false) (对复选框使用@change 并检查它是否为假)

 new Vue({ el: "#demo", data () { return { checked: false, } }, methods : { noEntry() { let password; password = !this.checked ? "" : prompt("Seul le personnel de la librairie ya accès, veuillez inscrire le mot de passe", ""); password === "administrations" ? this.checked = true : this.checked = false console.log(this.checked) } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <form action="#/login" > <input type="email" placeholder="Insérez votre adresse-mail pour créer votre compte"/> <input type="password" placeholder="Mettez y votre mot de passe"> <label for="admin"> Droits administrateurs </label> <input type="checkbox" id="admin" v-model="checked" @change="noEntry"> </form> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM