vue3.0加MongoDB加node的后台管理系统(一)

本文介绍了如何使用Vue3.0、Node.js和Mongoose搭建后台管理系统。首先,通过Vite快速创建Vue项目,并引入Ant Design of Vue。接着,讲解了如何设置路由和创建视图。在Node.js方面,文章详细阐述了项目初始化、引入Mongoose连接MongoDB、使用Express以及body-parser中间件。最后,讨论了JWT用于身份验证,并展示了创建登录注册接口的步骤。
摘要由CSDN通过智能技术生成

vue3.0的创建

npm install -g @vue/cli
yarn global add @vue/cli

Vite 是一个 web 开发构建工具,由于其原生 ES 模块导入方式,可以实现闪电般的冷服务器启动。

通过在终端中运行以下命令,可以使用 Vite 快速构建 Vue 项目。

npm init vite-app Vite-mongodb
cd Vite-mongodb
npm install
npm run dev

或者使用yarn的方式创建

yarn create vite-app Vite-mongodb
$ cd Vite-mongodb
$ yarn
$ yarn dev

当前项目目录为:
在这里插入图片描述
引入Ant Design of Vue

npm i --save ant-design-vue@next
// src/main.js
import antd from 'ant-design-vue'
import '../node_modules/ant-design-vue/dist/antd.css'

修改 createApp(App).mount(’#app’)

// createApp(App).mount('#app')
// 改为
// 创建app
const app = createApp(App)
// 注入antd
app.use(antd).mount('#app')

引入路由

npm install vue-router@next

在src下创建文件夹router
官方实例:

const router = createRouter({
   
  history: createWebHistory(),
  routes: [{
    path: '/:articleName', component: Article }],
})
// router/router.js
import {
    createRouter, createWebHistory } from "vue-router"
// reateWebHashHistory hash 路由
// createWebHistory history 路由
// createMemoryHistory 带缓存 history 路由
// parseQuery 查询参数反序列化
// stringifyQuery 查询参数序列化
// onBeforeRouteLeave 路由离开钩子
// 路由信息
const routes = [
  {
   
    path: "/login", // 登录页
    name: "login",
    component: () => import('../view/login/login.vue'),
  },
  {
   
    path: "/403",
    name: "403",
    component: () => import('../components/error/403.vue'),
  },
  {
   
    path: "/404",
    name: "404",
    component: () => import('../components/error/404.vue'),
  },
  {
   
    path: "/500",
    name: "500",
    component: () => import('../components/error/500.vue'),
  }
]
// 导出路由
const router = createRouter({
   
  history: createWebHistory(),
  routes
})
export default router;

在src下创建文件夹view,书写页面
在src/view/index.vue中定义页面的主入口

<template>
  <!-- 主页 -->
</template>
<script>
import {
     reactive, toRefs,onMounted, computed, watch,} from 'vue'
import {
     useRouter, useRoute } from "vue-router";
export default {
    
  setup () {
    
    const data = reactive({
    
    })
    // 进入页面
    onMounted(() => {
    
    })
    // 路由
    const routers = useRouter()
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值