下班前几分钟,我用几行代码搭建了个 Vue3 项目,CSS盒模型居中方法

本文介绍了如何在下班前快速搭建一个基于Vue3的项目,涉及Vue-Router的安装与配置,以及Vuex的状态管理。通过创建路由和设置状态管理器,帮助开发者构建单页面应用。
摘要由CSDN通过智能技术生成

更多 Element Plus 相关内容请前往官网:

一个 Vue 3 UI 框架 | Element Plus

此处不做展开。

三、引入路由 Vue-Router


Vue-Router 是 Vue.js 官方的路由管理器。它和 Vue.js 的核心深度集成,让构建单页面应用变得更加简单。

1、安装

npm install vue-router@4 -S

2、在 src 下新建 router 文件夹,且新建一个文件 index.js

可使用如下指令构建最简单的结构(也可在项目中直接创建)。

cd ./src

mkdir router

cd ./router

touch index.js

3、index.js 中的简单内容

import { createRouter, createWebHashHistory } from ‘vue-router’

const routes = [

{

path: ‘/’,

redirect: ‘/componentA’

},

{

path: ‘/componentA’,

name: ‘componentA’,

component: () => import(‘…/components/ComponentA.vue’)

},

{

path: ‘/componentB’,

name: ‘componentB’,

component: () => import(‘…/components/ComponentB.vue’)

}

];

const router = createRouter({

history: createWebHashHistory(),

routes

});

export default router;

4、在 main.js 中引入 router

// …

import router from ‘./router’

createApp(App).use(ElementPlus).use(router).mount(‘#app’)

5、在 App.vue 使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值