Vue+Vite項目初建(axios+Unocss+iconify)的實現(xiàn)
一. 創(chuàng)建項目
npx --package @vue/cli vue
項目成功啟動后,進入http://localhost:3200,即可進入創(chuàng)建好的頁面(假設(shè)啟動端口為3200)
二. 測試網(wǎng)絡(luò)通訊模塊
假設(shè)有本地服務(wù)器地址localhost:8000提供接口服務(wù),接口為localhost:8000/token,修改代碼
<script setup>
import {ref} from 'vue'
import axios from 'axios'
import qs from 'qs'
import 'unocss'
defineProps({
msg: String,
})
function clickTest() {
console.log("按鈕點擊")
// var axios = require('axios');
var data = qs.stringify({
'username': 'hahaha',
'password': '123456'
});
var config = {
method: 'post',
url: 'http://localhost:8000/token',
headers: {
'Access-Control-Allow-Credentials': 'True',
'Access-Control-Allow-Origin': '*/*'
},
data: data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
}
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<button v-on:click="clickTest">測試</button>
<p>
Check out
<a rel="external nofollow" target="_blank"
>create-vue</a
>, the official Vue + Vite starter
</p>
<p>
Install
<a rel="external nofollow" target="_blank">Volar</a>
in your IDE for a better DX
</p>
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>
執(zhí)行代碼,如果后端服務(wù)器執(zhí)行正常,就會有相應(yīng)的返回值

三. 集成、測試UnoCSS
1. 安裝
npm install -D unocss
2. 集成
修改 vite.config.js
import UnoCSS from 'unocss/vite'
新建 uno.config.js
import {defineConfig, presetUno, presetIcons, presetAttributify} from 'unocss'
import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
export default defineConfig({
presets: [
presetUno(), // 添加 UnoCSS 的默認樣式預(yù)設(shè)
presetAttributify(),
presetIcons({
warn: true,
prefix: ['i-'],
extraProperties: {
display: 'inline-block',
},
collections: {
me: FileSystemIconLoader('./src/assets/isme'),
fe: FileSystemIconLoader('./src/assets/feather'),
},
})
],
})以上代碼用于配置unocss到系統(tǒng)中,注意“collections”中的配置是自定義圖標(biāo)的路徑
3. 顯示
<div class="text-center text-red-500">
Hello World!
</div>
顯示出以上效果說明unocss配置成功。
4. 圖標(biāo)()
<div m2 f-c hover="op80">
<a i-carbon-logo-github text-3xl text-black rel="external nofollow" target="_blank" />
<div i-carbon:3d-cursor text-3xl text-blue />
<button text-green text-3xl class="i-carbon-sun" />
<i class="i-me:gitee mr-12 cursor-pointer"/> // 自定義圖標(biāo)
</div>
<div class="i-carbon:content-view w-1em h-1em"></div>
<div class="i-carbon:humidity w-1em h-1em"></div>
<div class="card">
<button type="button" @click="count++">count is {{ count }}</button>
<button v-on:click="clickTest">測試</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test HMR
</p>
</div>
最終顯示效果,基本完成前期開發(fā)配置需要

到此這篇關(guān)于Vue+Vite項目初建(axios+Unocss+iconify)的實現(xiàn)的文章就介紹到這了,更多相關(guān)Vue Vite項目初建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決
Vue項目devServer.proxy代理配置詳解的是一個非常常見的需求,下面這篇文章主要給大家介紹了關(guān)于vue.config.js中devServer.proxy配置說明及配置正確不生效問題解決的相關(guān)資料,需要的朋友可以參考下2023-02-02
基于cropper.js封裝vue實現(xiàn)在線圖片裁剪組件功能
這篇文章主要介紹了基于cropper.js封裝vue實現(xiàn)在線圖片裁剪組件功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-03-03
vue中el-table實現(xiàn)穿梭框(數(shù)據(jù)可以上移下移)
本文主要介紹了vue中el-table實現(xiàn)穿梭框(數(shù)據(jù)可以上移下移),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06
vue +elementui 導(dǎo)入CSV文件的方式
封裝一個公共js方法,使用papaparse解析CSV文件且返回數(shù)組格式,下面通過示例代碼介紹vue +elementui 導(dǎo)入CSV文件的方式,感興趣的朋友一起看看吧2024-04-04
Element?UI?table參數(shù)中的selectable的使用及遇到坑
這篇文章主要介紹了Element?UI?table參數(shù)中的selectable的使用及遇到的坑,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08

