最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用vue3.x+vite+element-ui+vue-router+vuex+axios搭建項目

 更新時間:2021年08月24日 11:39:13   作者:YuShiYue  
因為vue3出了一段時間了,element也出了基于vue3.x版本的element-plus,這篇文章就拿他們搭建一個項目,希望能給你帶來幫助

一. 參考文檔

vite官方文檔

vue3.x官方文檔

vue-router4.x官方文檔

vuex4.x官方文檔

element-ui3.x官方文檔

Ant Design Vue2.x官方文檔

axios文檔

二. vite搭建項目

  • 安裝
# npm 安裝
npm init vite@latest

# yarn 安裝
yarn create vite

# 快速安裝vue模板項目
yarn create vite my-vue-app --template vue

npm init vite@latest my-vue-app -- --template vue

image-20210818170557952

  • 運行
npm run dev 

# or
yarn dev

image-20210818170733034

三. 配置element-ui

  • 下載包

npm install element-plus --save

修改src/main.js

import { createApp } from 'vue'

import ElementPlus from 'element-plus';
import 'element-plus/lib/theme-chalk/index.css';

import App from './App.vue'

const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')

驗證是否配置成功

image-20210818171148345

如果組件要按需引入的話可以參考文檔介紹

image-20210818171247339

四. 配置vue-router

從vue2遷移

安裝

npm install vue-router@4

創(chuàng)建src/router/index.js文件

image-20210818172342806

import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/demo',
    name: 'demo',
    component: () => import('../views/demo.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router

修改main.js

import { createApp } from 'vue'
import ElementPlus from 'element-plus';
import 'element-plus/lib/theme-chalk/index.css';
// 引入路由配置
import router from './router/index'
import App from './App.vue'

const app = createApp(App)
app.use(ElementPlus)
// 注冊
app.use(router)
app.mount('#app')

修改App.vue添加路由視圖

<template>
  <el-button type="primary">按鈕</el-button>
  <router-view></router-view>
</template>

<script>
export default {
  name: 'app'
}
</script>

創(chuàng)建src/views/demo.vue文件

image-20210818172605669

經(jīng)過以上的過程,訪問http://localhost:3000/demo 就可以看到一下界面,表明我們的路由配置成功~

image-20210818172727082

五. 配置vuex 安裝

npm install vuex@next --save

創(chuàng)建src/store/index.js文件

image-20210818173206269

import { createStore } from "vuex";

const store = createStore({
  state () {
    return {
      app: '我是app'
    }
  },
  mutations: {

  },
  actions: {

  }
})

export default store

修改src/main.js

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

const app = createApp(App)
app.use(ElementPlus)
app.use(router)
// 注冊
app.use(store)
app.mount('#app')

在App.vue中查看是否配置成功

image-20210818173322287

能夠成功打印測配置成功

image-20210818173340721

六. 配置axios

安裝

npm install axios -S

創(chuàng)建src/utils/request.js

import axios from 'axios'

const services = axios.create({
  baseURL: 'https://api.apiopen.top',
  timeout: 6000
})

// 請求攔截
services.interceptors.request.use(config => {
  // 在這可以添加一些請求頭的邏輯,如配置token
  return config
}, error => {
  return Promise.reject(error)
})

// 響應攔截
services.interceptors.response.use(response => {
  // 在這可以根據(jù)實際后臺的響應值去進行判斷,如code: 0 或者登錄失效跳轉(zhuǎn)到登錄頁等
  return response.data
}, error => {
  return Promise.reject(error)
})

export default services

image-20210818175532400

創(chuàng)建src/api/app.js配置氣你跪求方法

import request from '../utils/request'

export const send = () => {
  return request({
    url: '/getJoke',
    method: 'get',
    params: {
      page: 1,
      count: 2,
      type: 'video'
    }
  })
}

image-20210818175614712

在App.vue引入測試

<template>
  <el-button type="primary">按鈕</el-button>
  <router-view></router-view>
</template>

<script>
// 引入請求方法 
import { send } from "./api/app";
export default {
  name: "app",
  async mounted() {
    console.log("store>>>", this.$store.state.app);
    // 請求
    const res = await send()
    console.log('res>>>', res)
  },
};
</script>

查看瀏覽器是否請求成功

image-20210818175730709

七. 總結(jié)

經(jīng)過以上幾步就可以搭建一個簡單的vue工程化項目,但是實際開發(fā)當中肯定不能這么簡單,比如別名的配置,這個時候就需要修改vite.config.js去進行別名的配置,還有路由權(quán)限的控制以及ui庫sass變量的替換等等…

本篇文章就到這里了,希望能給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!

相關(guān)文章

  • java對圖片進行壓縮和resize縮放的方法

    java對圖片進行壓縮和resize縮放的方法

    本篇文章主要介紹了java對圖片進行壓縮和resize調(diào)整的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Springboot通過谷歌Kaptcha?組件生成圖形驗證碼功能

    Springboot通過谷歌Kaptcha?組件生成圖形驗證碼功能

    Kaptcha是谷歌開源的一款簡單實用的圖形驗證碼組件。我個人推薦它的最大原因是容易上手,采用約定大于配置的方式,快速契合到項目中,這篇文章主要介紹了Springboot通過谷歌Kaptcha組件生成圖形驗證碼的方法,需要的朋友可以參考下
    2023-05-05
  • springboot構(gòu)建docker鏡像并推送到阿里云

    springboot構(gòu)建docker鏡像并推送到阿里云

    本文主要介紹了springboot構(gòu)建docker鏡像并推送到阿里云,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-05-05
  • Java實現(xiàn)curl調(diào)用帶參數(shù)接口方法

    Java實現(xiàn)curl調(diào)用帶參數(shù)接口方法

    本文主要介紹了Java實現(xiàn)curl調(diào)用帶參數(shù)接口方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2025-04-04
  • jdk15的安裝與配置全過程記錄

    jdk15的安裝與配置全過程記錄

    這篇文章主要給大家介紹了關(guān)于jdk15的安裝與配置,文中通過圖文介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • springboot定時任務詳解

    springboot定時任務詳解

    這篇文章主要介紹了springboot定時任務的相關(guān)資料,幫助大家更好的理解和使用springboot框架,感興趣的朋友可以了解下
    2021-01-01
  • java中棧和隊列的實現(xiàn)和API的用法(詳解)

    java中棧和隊列的實現(xiàn)和API的用法(詳解)

    下面小編就為大家?guī)硪黄猨ava中棧和隊列的實現(xiàn)和API的用法(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • Spring Boot實現(xiàn)郵件發(fā)送必會的5種姿勢

    Spring Boot實現(xiàn)郵件發(fā)送必會的5種姿勢

    這篇文章主要給大家介紹了關(guān)于Spring Boot實現(xiàn)郵件發(fā)送必會的5種姿勢,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Spring Boot具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-07-07
  • Spring boot攔截器實現(xiàn)IP黑名單的完整步驟

    Spring boot攔截器實現(xiàn)IP黑名單的完整步驟

    這篇文章主要給大家介紹了關(guān)于Spring boot攔截器實現(xiàn)IP黑名單的完整步驟,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Spring boot攔截器具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2020-06-06
  • SpringBoot MongoDB與MongoDB GridFS基本使用

    SpringBoot MongoDB與MongoDB GridFS基本使用

    這篇文章主要為大家介紹了SpringBoot MongoDB與MongoDB GridFS基本使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07

最新評論

罗甸县| 措勤县| 尼木县| 封开县| 柳江县| 昭平县| 额济纳旗| 大丰市| 光山县| 新营市| 桂平市| 翁牛特旗| 花垣县| 那坡县| 全州县| 黔东| 沈阳市| 新野县| 青川县| 正定县| 鱼台县| 承德市| 万全县| 介休市| 怀仁县| 宁河县| 赤城县| 南康市| 安泽县| 伽师县| 任丘市| 铁力市| 行唐县| 肃宁县| 嵊泗县| 克东县| 玛沁县| 塘沽区| 宜章县| 六枝特区| 托克托县|