Vue+Vite項(xiàng)目初建(axios+Unocss+iconify)的實(shí)現(xiàn)
一. 創(chuàng)建項(xiàng)目
npx --package @vue/cli vue
項(xiàng)目成功啟動(dòng)后,進(jìn)入http://localhost:3200,即可進(jìn)入創(chuàng)建好的頁(yè)面(假設(shè)啟動(dòng)端口為3200)
二. 測(cè)試網(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("按鈕點(diǎn)擊") // 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">測(cè)試</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í)行正常,就會(huì)有相應(yīng)的返回值
三. 集成、測(cè)試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 的默認(rèn)樣式預(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>
顯示出以上效果說(shuō)明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">測(cè)試</button> <p> Edit <code>components/HelloWorld.vue</code> to test HMR </p> </div>
最終顯示效果,基本完成前期開(kāi)發(fā)配置需要
到此這篇關(guān)于Vue+Vite項(xiàng)目初建(axios+Unocss+iconify)的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Vue Vite項(xiàng)目初建內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue.config.js中devServer.proxy配置說(shuō)明及配置正確不生效問(wèn)題解決
Vue項(xiàng)目devServer.proxy代理配置詳解的是一個(gè)非常常見(jiàn)的需求,下面這篇文章主要給大家介紹了關(guān)于vue.config.js中devServer.proxy配置說(shuō)明及配置正確不生效問(wèn)題解決的相關(guān)資料,需要的朋友可以參考下2023-02-02vue3.0+echarts實(shí)現(xiàn)立體柱圖
這篇文章主要為大家詳細(xì)介紹了vue3.0+echarts實(shí)現(xiàn)立體柱圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09基于cropper.js封裝vue實(shí)現(xiàn)在線圖片裁剪組件功能
這篇文章主要介紹了基于cropper.js封裝vue實(shí)現(xiàn)在線圖片裁剪組件功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-03-03vue中el-table實(shí)現(xiàn)穿梭框(數(shù)據(jù)可以上移下移)
本文主要介紹了vue中el-table實(shí)現(xiàn)穿梭框(數(shù)據(jù)可以上移下移),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06vue +elementui 導(dǎo)入CSV文件的方式
封裝一個(gè)公共js方法,使用papaparse解析CSV文件且返回?cái)?shù)組格式,下面通過(guò)示例代碼介紹vue +elementui 導(dǎo)入CSV文件的方式,感興趣的朋友一起看看吧2024-04-04Element?UI?table參數(shù)中的selectable的使用及遇到坑
這篇文章主要介紹了Element?UI?table參數(shù)中的selectable的使用及遇到的坑,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08Vue.js 實(shí)現(xiàn)tab切換并變色操作講解
這篇文章主要介紹了Vue.js 實(shí)現(xiàn)tab切換并變色操作講解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09