当前位置:   article > 正文

Vue3+element-plus实现后台管理系统_后台管理系统element-plus框架

后台管理系统element-plus框架

背景(未完待续)

 环境:node.js软件 、Vs code、vite、elemnt-plus、windicss(样式框架)

 

第一节课

  1、首先,使用npm 命令构建项目( vscode安装的插件 vscode中文显示插件   2、高亮提示插件volar   3、vue 3 sni 代码提示)

快速上手 | Vue.js


   a. npm -v 查看node.js 版本

   b.  npm  config get registry   查看注册镜像是不是国内的,如果不是则执行以下命令注册成国内的。

   c.  npm config set registry=https://registry.npmmirror.com  切换成国内镜像

        代理地址淘宝 registry=https://registry.npmmirror.com


   d.  初始化工程  npm init vue@latest shop-admin  -- --template vue

       提示
       cd shop-admin
       npm install
       npm run dev  (启动项目)

    按提示步骤依次运行
    
   e、引入elemnt-plus 插件
      安装: npm install element-plus --save

       main.js引入
       import ElementPlus from 'element-plus'
       import 'element-plus/dist/index.css'
       
       app.use(ElementPlus)

    
    f、引入样式框架windicss工具库
       中文地址:https://cn.windicss.org/

        打开指引--vite 安装
        npm i -D vite-plugin-windicss windicss
      
    g、WindiCSS IntelliSense代码提示插件vs code 里面安装

第二课、vue路由安装

入门 | Vue Router

新建router文件,配置如下代码

然后在main.js中引入

 为了方便查找src目录,在vite.config.js中配置别名。

 在App.vue引入

 第三课 、404页面

在路由中配置 

 第四课、登录页面开发

  1. <template>
  2. <el-row class="min-h-screen min-w-screen bg-indigo-500">
  3. <el-col :lg="16" :md="12" class="login_left_md">
  4. <div class="flex-col">
  5. <div>欢迎光临</div>
  6. <div>此站点是《vue3 + vite实战商城后台开发》视频课程的演示地址</div>
  7. </div>
  8. </el-col>
  9. <el-col :lg="8" :md="12" class="login_module">
  10. <h2 class="font-bold text-3xl text-gray-800">欢迎回来</h2>
  11. <div class="">
  12. <span class="h-1 w-16 bg-gray-200"></span>
  13. <span>账号密码登录</span>
  14. <span class="h-[1px] w-16 bg-gray-200"></span>
  15. </div>
  16. <el-form :rules="rules" :model="form" ref="formRef" class="w-[250px]">
  17. <el-form-item prop="username">
  18. <!-- 指定校验 prop="username" -->
  19. <el-input v-model="form.username" placeholder="请输入用户名">
  20. <template #prefix>
  21. <el-icon>
  22. <User />
  23. </el-icon>
  24. </template>
  25. </el-input>
  26. </el-form-item>
  27. <!-- 指定校验 prop="password" -->
  28. <el-form-item prop="password">
  29. <el-input v-model="form.password" placeholder="请输入密码" type="password" show-password>
  30. <template #prefix>
  31. <el-icon>
  32. <Lock />
  33. </el-icon>
  34. </template>
  35. </el-input>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button round color="#626aef" class="w-[250px]" type="primary" @click="onSubmit">登 录</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </el-col>
  42. </el-row>
  43. </template>
  44. <script setup>
  45. import { ref, reactive } from 'vue'
  46. import { User, Lock } from '@element-plus/icons-vue'
  47. import { login } from '~/api/manager'
  48. import { ElNotification } from 'element-plus'
  49. import { useRouter } from 'vue-router'
  50. const router = useRouter()
  51. // do not use same name with ref
  52. const form = reactive({
  53. username: "",
  54. password: ""
  55. })
  56. // 校验规则
  57. const rules = {
  58. username: [
  59. {
  60. required: true,
  61. message: '用户名不能为空',
  62. trigger: 'blur'
  63. },
  64. {
  65. min: 3,
  66. max: 10,
  67. message: '用户名长度必须为3-10',
  68. trigger: 'blur'
  69. }],
  70. password: [
  71. {
  72. required: true,
  73. message: '用户名不能为空',
  74. trigger: 'blur'
  75. },
  76. {
  77. min: 3,
  78. max: 10,
  79. message: '用户名长度必须为3-10',
  80. trigger: 'blur'
  81. }
  82. ]
  83. }
  84. const formRef = ref(null)
  85. // 登录按钮
  86. const onSubmit = () => {
  87. formRef.value.validate((valid) => {
  88. if (!valid) {
  89. return false
  90. }
  91. login(form.username, form.password)
  92. .then(res => {
  93. console.log(res.data.data);
  94. // 提示成功
  95. ElNotification({
  96. message: "登录成功",
  97. type: 'success',
  98. duration: 3000
  99. })
  100. // 存储token和用户相关信息,下节课讲
  101. // 跳转到后台首页
  102. router.push("/index")
  103. })
  104. .catch(err => {
  105. ElNotification({
  106. message: err.response.data.msg || "请求失败",
  107. type: 'error',
  108. duration: 3000
  109. })
  110. })
  111. })
  112. }
  113. </script>
  114. <style scoped>
  115. .login_module {
  116. @apply bg-light-50 flex items-center justify-center flex-col;
  117. }
  118. .login_module>div {
  119. @apply flex items-center justify-center my-5 text-gray-300 space-x-2;
  120. }
  121. .login_left_md {
  122. @apply flex items-center justify-center;
  123. }
  124. .login_left_md>div>div:first-child {
  125. @apply font-bold text-5xl text-light-50 mb-4
  126. }
  127. .login_left_md>div>div:last-child {
  128. @apply text-gray-200 text-sm;
  129. }
  130. </style>

源码地址

https://download.csdn.net/download/shi450561200/87780611

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/383422
推荐阅读