vue3+vue-router+ts+vite+element-plus+pinia build management background

  1. Install Vue3
    First, you need to install Vue3, which can be installed via npm. Enter the following command at the command line:
    npm install vue@next
    
  2. Install Vue Router
    Vue Router is installed to implement the routing function, and it can also be installed through npm. Enter the following command at the command line:
    npm install vue-router@4
    
  3. Install TypeScript
    TypeScript is a typed JavaScript that improves code maintainability and readability. It can also be installed via npm. Enter the following command at the command line:
    npm install typescript
    
  4. Install Vite
    Vite is a fast development server and build tool that can improve development efficiency. It can also be installed via npm. Enter the following command at the command line:
    npm install vite
    
  5. Install Element Plus
    Element Plus is a Vue3 component library based on Element UI, which can improve the efficiency of UI development. It can also be installed via npm. Enter the following command at the command line:
    npm install element-plus
    
  6. Install Pinia
    Pinia is a Vue3 state management library that can help us manage the state of the application. It can also be installed via npm. Enter the following command at the command line:
    npm install pinia
    
  7. Create a Vue3 project
    Enter the following command at the command line to create a Vue3 project:
    vue create my-app
    
  8. Configure Vite
    Create a vite.config.ts file in the project root directory and add the following content:
    import { defineConfig } from 'vite'
    import vue from '@vitejs/plugin-vue'
    
    export default defineConfig({
      plugins: [vue()]
    })
    
  9. Configure Vue Router
    to create a router directory under the src directory, create an index.ts file under this directory, and add the following content:
    import { createRouter, createWebHistory } from 'vue-router'
    import Home from '../views/Home.vue'
    
    const routes = [
      {
        path: '/',
        name: 'Home',
        component: Home
      }
    ]
    
    const router = createRouter({
      history: createWebHistory(process.env.BASE_URL),
      routes
    })
    
    export default router
    
  10. Configure Pinia
    to create a store directory under the src directory, create an index.ts file under this directory, and add the following content:
import { createPinia } from 'pinia'

export const store = createPinia()
  1. Introducing Element Plus

Add the following to the main.ts file:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { store } from './store'
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'

createApp(App)
  .use(router)
  .use(store)
  .use(ElementPlus)
  .mount('#app')
  1. Create pages and components
    Create a Home.vue file in the views directory and add the following content:
<template>
  <div>
    <h1>Home</h1>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Home'
})
</script>

Create a Header.vue file in the components directory and add the following content:

<template>
  <div>
    <h1>Header</h1>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Header'
})
</script>
  1. Configure routing
    Add the following content to the index.ts file in the router directory:
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Header from '../components/Header.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/header',
    name: 'Header',
    component: Header
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
  1. Use the Header component in App.vue
    Add the following to the App.vue file:
<template>
  <div id="app">
    <Header />
    <router-view />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import Header from './components/Header.vue'

export default defineComponent({
  name: 'App',
  components: {
    Header
  }
})
</script>
  1. Run the project
    Enter the following command at the command line to run the project:
npm run dev

Then visit http://localhost:3000 in the browser to see the effect.

The above is the general process of building the management background, and the specific implementation needs to be adjusted and improved according to the needs.

In addition, you also need to learn and master some related technologies and tools, such as:

  1. Basic knowledge of HTML, CSS and JavaScript
    This is the basis of Web development, and it is necessary to master the basic syntax and common skills of HTML, CSS and JavaScript.

  2. Vue3 framework
    Vue3 is a popular JavaScript framework that can help us quickly build interactive and high-performance web applications.

  3. TypeScript language
    TypeScript is a typed JavaScript that improves code maintainability and readability.

  4. Vite Tools
    Vite is a fast development server and build tool that can improve development efficiency.

  5. Vue Router routing
    Vue Router is the official routing manager of the Vue3 framework, which can help us realize the jump and routing control between pages.

  6. Pinia state management library
    Pinia is a Vue3 state management library that can help us manage the state of the application.

  7. Element Plus component library
    Element Plus is a Vue3 component library based on Element UI, which can improve the efficiency of UI development.

Continuous learning and practice are required to master these technologies and tools, so as to build an efficient, reliable, and easy-to-maintain management background.

Guess you like

Origin blog.csdn.net/qq_44848480/article/details/129861700
Recommended