LoginView.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="bg-gray-200 flex items-center justify-center min-h-screen">
  3. <form class="bg-white p-8 rounded-lg shadow-md w-96 space-y-4">
  4. <h2 class="text-2xl font-bold text-gray-800 text-center">登录</h2>
  5. <div>
  6. <label for="username" class="block text-gray-600">用户名</label>
  7. <input id="username" v-model="username" type="text" class="w-full px-4 py-2 border border-gray-300 rounded focus:outline-none focus:border-purple-500" />
  8. </div>
  9. <div>
  10. <label for="password" class="block text-gray-600">密码</label>
  11. <input id="password" v-model="password" type="password" class="w-full px-4 py-2 border border-gray-300 rounded focus:outline-none focus:border-purple-500" />
  12. </div>
  13. <div class="flex items-center">
  14. <input id="remember" v-model="remember" type="checkbox" class="mr-2" />
  15. <label for="remember" class="text-gray-600 text-sm">记住我</label>
  16. </div>
  17. <button @click.prevent="login" class="w-full bg-purple-600 text-white font-bold py-2 rounded hover:bg-purple-700">登录</button>
  18. </form>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. username: '',
  26. password: '',
  27. remember: false,
  28. };
  29. },
  30. methods: {
  31. login() {
  32. // Simple validation
  33. if (!this.username || !this.password) {
  34. alert('用户名和密码不能为空');
  35. return;
  36. }
  37. // Dummy login logic
  38. if (this.username === 'admin' && this.password === 'admin') {
  39. alert('登录成功');
  40. // Redirect to home page
  41. this.$router.push('/');
  42. } else {
  43. alert('用户名或密码错误');
  44. }
  45. },
  46. },
  47. };
  48. </script>
  49. <style scoped>
  50. /* Additional styles can be added here if needed */
  51. </style>