Vue3基础库引入及部分第三方库的引入使用

一、路由

1、路由

  下载路由  npm install vue-router@4

 2、创建文件  src下创建router文件夹

在router文件下创建router.ts文件
        
import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from "vue-router"
export const IndexRouter = []
const routes: Array<RouteRecordRaw> = [
    //一级路由重定向
    {
        path: '/:catchAll(.*)', redirect: '/index'
    },
    {
        path: '/index',
        component: () => import("../pages/index/index.vue"),//路由懒加载
        // 二级路由
        children: [
            {
                path: '/home',
                component: () => import('../views/home.vue'),
            }
        ]
    },
    ...IndexRouter
]

const router = createRouter({
    history: createWebHistory(),//设置路由模式
    // history:createWebHistory(process.env.BASE_URL),
    routes
})
export default router

3、main.ts引入使用

import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
const app = createApp(App)
app.use(router).mount('#app')

4、设置路由出口

<script setup lang="ts">

</script>

<template>
  <!-- 一级路由出口 -->
  <router-view></router-view>
</template>

<style scoped></style>

5.使用路由跳转

。。。

 

二、vuex

三、Element-Plus

安装

# NPM
$ npm install element-plus --save

# Yarn
$ yarn add element-plus

# pnpm
$ pnpm install element-plus

引入使用

import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
import ElementPlus from "element-plus"
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'//icon
const app = createApp(App)
// ElementPlus 的icon
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(router).use(ElementPlus).mount('#app')

四、全局

1、全局组件

import vHead from "./head/head.vue";
// export default function install(app: any) {
//     app.component('vMap', vHead)
// }

export const componentPligin = {
    install(app: any) {
        // app.component('组件名字',组件配置对象)
        app.component('vHead', vHead)

    }
}
main.ts

import {componentPligin} from './components/index'
const app = createApp(App)

app.use(router).use(ElementPlus).use(componentPligin).mount('#app')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值