<p>&quot;<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        // 登录成功后的操作\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\n<template>\n  &lt;div id=&quot;cloud&quot;&gt;&lt;span class=&quot;shadow&quot;&gt;</span></div>\n  &lt;div id=&quot;cloud1&quot;&gt;&lt;span class=&quot;shadow&quot;&gt;</span></div>\n  &lt;div id=&quot;cloud2&quot;&gt;&lt;span class=&quot;shadow&quot;&gt;</span></div>\n  &lt;div class=&quot;login-page&quot;&gt;\n    &lt;div v-show=&quot;show&quot; class=&quot;login-container&quot;&gt;\n      &lt;h2 class=&quot;login-title&quot;&gt;登录</h2>\n      &lt;el-form class=&quot;login-form&quot;&gt;\n        &lt;el-form-item label=&quot;账号:&quot;&gt;\n          &lt;el-input v-model=&quot;username&quot; type=&quot;text&quot; style=&quot;width: 250px;&quot; placeholder=&quot;手机号&quot; required&gt;</el-input>\n        </el-form-item>\n        &lt;el-form-item label=&quot;密码:&quot;&gt;\n          &lt;el-input v-model=&quot;password&quot; type=&quot;password&quot; style=&quot;width:250px&quot; placeholder=&quot;密码&quot; show-password required/&gt; </el-form-item>\n        <el-form-item>\n          <!-- :imgs=\"imgs\" 自定义图片-->\n          &lt;Vcode v-if=&quot;show&quot; :isShow=&quot;isShow&quot; :onClose=&quot;onClose&quot; :onSuccess=&quot;onSuccess&quot; /&gt;\n          &lt;el-button class=&quot;login-button&quot; type=&quot;primary&quot; @click=&quot;login&quot;&gt;登录</el-button>\n        </el-form-item>\n      </el-form>\n      &lt;div class=&quot;register-link&quot;&gt;\n        &lt;router-link to=&quot;/register&quot;&gt;\n          &lt;el-button type=&quot;info&quot; style=&quot;width: 100%;&quot;&gt;注册</el-button>\n        </router-link>\n      </div>\n    </div>\n  </div>\n</template>\n\n<style>\n.login-page {\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  height: 100vh;\n}\n\n.login-container {\n  padding: 20px;\n  background-color: #fff;\n  border-radius: 6px;\n  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n}\n\n.login-title {\n  text-align: center;\n  margin-bottom: 20px;\n}\n\n.login-form {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n}\n\n.register-link {\n  text-align: center;\n  margin-top: 20px;\n}\n\n#cloud {\n  position: absolute;\n  z-index: 0;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/cloud1.png&quot;) no-repeat;\n  width: 460px;\n  height: 290px;\n  left: -80px;\n  top: -30px;\n  background-size: cover;\n  animation: move-clouds-back 60s linear infinite;\n  opacity: 0.8;\n}\n\n#cloud .shadow {\n  position: absolute;\n  z-index: 0;\n  width: 100%;\n  height: 100%;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/shadow.png&quot;) no-repeat;\n  background-size: cover;\n  bottom: -40px;\n  opacity: 0.8;\n}\n\n#cloud1 {\n  position: absolute;\n  z-index: 0;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/cloud2.png&quot;) no-repeat;\n  width: 500px;\n  height: 310px;\n  right: -80px;\n  top: 90px;\n  background-size: cover;\n  animation: move-clouds 40s linear infinite;\n  opacity: 0.8;\n}\n\n#cloud1 .shadow {\n  position: absolute;\n  z-index: 0;\n  width: 100%;\n  height: 100%;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/shadow.png&quot;) no-repeat;\n  background-size: cover;\n  bottom: -40px;\n  opacity: 0.8;\n}\n\n#cloud2 {\n  position: absolute;\n  z-index: 0;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/cloud3.png&quot;) no-repeat;\n  width: 400px;\n  height: 250px;\n  right: -80px;\n  top: 15px;\n  background-size: cover;\n  animation: move-clouds-back 60s linear infinite;\n  opacity: 0.8;\n}\n\n#cloud2 .shadow {\n  position: absolute;\n  z-index: 0;\n  width: 100%;\n  height: 100%;\n  background: url(&quot;https://cdn.jsdelivr.net/gh/niannings/shadow.png&quot;) no-repeat;\n  background-size: cover;\n  bottom: -40px;\n  opacity: 0.8;\n}\n\n@keyframes move-clouds-back {\n  0% {\n    transform: translateX(0px);\n  }\n  100% {\n    transform: translateX(-1300px);\n  }\n}\n\n@keyframes move-clouds {\n  0% {\n    transform: translateX(0px);\n  }\n  100% {\n    transform: translateX(1300px);\n  }\n}\n</style>\n</p>
Vue.js 登录页面 - 使用 axios 和 vue3-puzzle-vcode 实现