<p>{
&quot;title&quot;: &quot;login.vue&quot;,
&quot;description&quot;: &quot;使用 Vue.js 和 Vue3-Puzzle-Vcode 组件构建一个安全的登录页面,包括用户名、密码输入和验证码验证功能,提供详细的代码示例和说明。&quot;,
&quot;keywords&quot;: &quot;Vue.js, 登录页面, 验证码, Vue3-Puzzle-Vcode, 组件, 代码示例, 前端开发&quot;,
&quot;content&quot;: &quot;import axios from 'axios';\nimport Vcode from &quot;vue3-puzzle-vcode&quot;;\nimport { ref } from 'vue';\n\nconst isShow = ref(false);\n\nconst login = () =&gt; {\n  isShow.value = true;\n};\n\nconst onClose = () =&gt; {\n  isShow.value = false;\n};\n\nconst onSuccess = () =&gt; {\n  onClose(); // 验证成功,需要手动关闭模态框\n};\n\nconst show = ref(true)\n\n\nlogin.js\nimport axios from 'axios';\n\nexport default {\n  name: 'loginPage',\n  data() {\n    return {\n      username: '',\n      password: '',\n    };\n  },\n  methods: {\n    login(e) {\n      e.preventDefault();\n      // 登录逻辑\n      axios.post(&quot;http://nn.nncoding.icu:8080/api/login&quot;, {\n        username: this.username,\n        password: this.password\n      }).then(result =&gt; {\n        console.log(&quot;登录成功&quot;);\n        console.log(result);\n      }).catch(error =&gt; {\n        alert(&quot;登录失败,用户名或密码错误&quot;);\n        console.log(error);\n        console.log(error.response.data.message);\n      });\n    },\n  },\n};\n\n\n<template>\n  <div>\n    &lt;form @submit=&quot;login&quot;&gt;\n      &lt;input type=&quot;text&quot; v-model=&quot;username&quot; placeholder=&quot;Username&quot; required&gt;\n      &lt;input type=&quot;password&quot; v-model=&quot;password&quot; placeholder=&quot;Password&quot; required&gt;\n      &lt;button type=&quot;submit&quot;&gt;Login</button>\n    </form>\n    &lt;Vcode v-if=&quot;show&quot; :isShow=&quot;isShow&quot; :onClose=&quot;onClose&quot; :onSuccess=&quot;onSuccess&quot; /&gt;\n  </div>\n</template>\n\n<script>\nimport axios from 'axios';\nimport Vcode from &quot;vue3-puzzle-vcode&quot;;\nimport { ref } from 'vue';\n\nexport default {\n  name: 'loginPage',\n  components: {\n    Vcode\n  },\n  data() {\n    return {\n      username: '',\n      password: '',\n      isShow: ref(false),\n      show: ref(true)\n    };\n  },\n  methods: {\n    login(e) {\n      e.preventDefault();\n      // 登录逻辑\n      axios.post(&quot;http://nn.nncoding.icu:8080/api/login&quot;, {\n        username: this.username,\n        password: this.password\n      }).then(result =&gt; {\n        console.log(&quot;登录成功&quot;);\n        console.log(result);\n      }).catch(error =&gt; {\n        alert(&quot;登录失败,用户名或密码错误&quot;);\n        console.log(error);\n        console.log(error.response.data.message);\n      });\n    },\n    onClose() {\n      this.isShow.value = false;\n    },\n    onSuccess() {\n      this.onClose(); // 验证成功,需要手动关闭模态框\n    }\n  },\n};\n</script>
\n&quot;}</p>
Vue.js 登录页面 - 使用 Vue3-Puzzle-Vcode 进行验证码验证