ð ã¯ã€ãã¯ã¹ã¿ãŒã - ããªãã®Vantã®çŽ æŽãããæ ãå§ãããïŒ â
Vantã®çŽ æŽãããæ ãžããããïŒð ã¢ãã€ã«éçºã«åããŠè§Šããåå¿è ã®æ¹ãããéçºå¹çãåäžããããããã©ã³éçºè ãŸã§ããã®ã¬ã€ããããªãã®æã芪åãªã¬ã€ãã«ãªããŸããæãç°¡åã§çè§£ããããæ¹æ³ã§ããŒãããå§ããŠãã¹ããããã€ã¹ãããã§çŽ æŽãããã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ãæ§ç¯ããæ¹æ³ããæ¡å ããŸãïŒ
ðŠ ã€ã³ã¹ããŒã« - Vantãããªãã®ãããžã§ã¯ãã«è¿ããã â
åªç§ãªå人ãããŒã ã«è¿ããããã«ããŸãVantããããžã§ã¯ãã«æåŸ ããŸãããïŒããªããæãæ £ã芪ããã ããã±ãŒãžãããŒãžã£ãŒãéžãã§ã1è¡ã®ã³ãã³ãã§å®äºã§ãïŒ
npm ã€ã³ã¹ããŒã« - ã¯ã©ã·ãã¯ãªéžæ â
npm install vantyarn ã€ã³ã¹ããŒã« - é«é â
yarn add vantpnpm ã€ã³ã¹ããŒã« - ã¹ããŒã¹ç¯çŽ â
pnpm add vantð¡ ãã³ãïŒpnpmã®äœ¿çšããå§ãããŸããã€ã³ã¹ããŒã«é床ãéãã ãã§ãªãã倧éã®ãã£ã¹ã¯ã¹ããŒã¹ãç¯çŽã§ããŸãïŒ
ð ã³ã³ããŒãã³ãã®å°å ¥ - 3ã€ã®æ¹æ³ããã£ãšããªãã«åããã®ããããŸã â
æ¹æ³1ïŒèªåãªã³ããã³ãå°å ¥ïŒæšå¥šïŒ- æ ãè ã«çŠé³ïŒ â
ããã¯æãæéã®ããããªãæ¹æ³ã§ã芪åãªå·äºããããã®ããã«ãå¿ èŠãªã³ã³ããŒãã³ããèªåçã«æºåããŠãããŸãããŸã£ããæ°ã«ããå¿ èŠã¯ãããŸããïŒ
ãã©ã°ã€ã³ã®ã€ã³ã¹ããŒã«ïŒ
npm install unplugin-vue-components -Dvite.config.jsã®èšå®ïŒ
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [VantResolver()],
}),
],
})ð¯ ãªããã®æ¹æ³ããå§ãããã®ã§ããïŒ
- â èªåãªã³ããã³ãå°å ¥ããã³ãã«ãµã€ãºæå°
- â æåã€ã³ããŒãäžèŠãéçºå¹çæé«
- â TypeScriptãµããŒããåãã³ãå®ç§
æ¹æ³2ïŒæåãªã³ããã³ãå°å ¥ - æ£ç¢ºãªå¶åŸ¡ â
ãã¹ãŠã®è©³çްãå®å šã«ææ¡ãããæ¹ã«ããã®æ¹æ³ã¯å°å ¥ããã³ã³ããŒãã³ããå®å šã«å¶åŸ¡ã§ããŸãïŒ
import { createApp } from 'vue'
import { Button, Cell } from 'vant'
const app = createApp()
app.use(Button)
app.use(Cell)æ¹æ³3ïŒå®å šå°å ¥ - ã·ã³ãã«ã§åŒ·å â
è¿ éãªãããã¿ã€ãéçºãå°èŠæš¡ãããžã§ã¯ãã«é©ããŠããããã¹ãŠã®ã³ã³ããŒãã³ããäžåºŠã«å°å ¥ããŸãïŒ
import { createApp } from 'vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp()
app.use(Vant)â ïž æ³šæïŒå®å šå°å ¥ã¯ãã³ãã«ãµã€ãºãå¢å ãããŸããæ¬çªç°å¢ã§ã¯ãªã³ããã³ãå°å ¥ã®äœ¿çšããå§ãããŸãã
ð¡ åºæ¬çãªäœ¿ãæ¹ - ããªãã®æåã®Vantã³ã³ããŒãã³ã â
æåã®ã³ã³ããŒãã³ã - Hello VantïŒ â
æãã·ã³ãã«ãªãã¿ã³ããå§ããŠãVantã®é åãæããŠã¿ãŸãããïŒ
<template>
<div>
<van-button type="primary">äž»èŠãã¿ã³</van-button>
<van-button type="success">æåãã¿ã³</van-button>
<van-button type="danger">å±éºãã¿ã³</van-button>
<van-button type="warning">èŠåãã¿ã³</van-button>
</div>
</template>ðš èŠããŸãããïŒ ãããæ°è¡ã®ã³ãŒãã§ã4ã€ã®ç°ãªãã¹ã¿ã€ã«ã®çŸãããã¿ã³ãæã«å ¥ããŸããïŒ
ã¢ãã€ã«å¯Ÿå¿ - ããªãã®ã¢ããªã±ãŒã·ã§ã³ãããããããã€ã¹ã§å®ç§ã«è¡šç€º â
HTMLã®ããããŒã«ãã®éæ³ã®metaã¿ã°ã远å ãããšãããªãã®ã¢ããªã±ãŒã·ã§ã³ã«ã察å¿ã¡ã¬ãããããããããªå¹æããããŸãïŒ
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">Remå¯Ÿå¿ - çæ¯æ¡å€§çž®å°ã®éæ³ â
ç°ãªããµã€ãºã®ããã€ã¹ã§ããªãã®ã¢ããªã±ãŒã·ã§ã³ãå®ç§ãªæ¯çã§ä¿ã¡ããã§ããïŒRem察å¿ãããªãã®éæ³ã®æã§ãïŒ
postcss-pxtoremã®ã€ã³ã¹ããŒã«ïŒ
npm install postcss-pxtorem -Dpostcss.config.jsã®èšå®ïŒ
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5, // 讟计皿宜床ç1/10
propList: ['*'], // éèŠèœ¬æ¢ç屿§ïŒ*衚瀺ææ
},
},
}ð® éæ³ã®åçïŒãã®èšå®ã«ãããããªããèšè¿°ããpxåäœãèªåçã«remã«å€æãããçæ¯æ¡å€§çž®å°ãå®çŸãããŸãïŒ
ðš ããŒãã«ã¹ã¿ãã€ãº - ç¬èªã®ããžã¥ã¢ã«ã¹ã¿ã€ã«ãåµãåºã â
CSS倿°ã®ã«ã¹ã¿ãã€ãº - ã¯ã³ã¯ãªãã¯ã§ããŒãå€æŽ â
ã¢ããªã±ãŒã·ã§ã³ã®ããŒãã«ã©ãŒã倿Žãããã§ããïŒããã€ãã®CSS倿°ã倿Žããã ãã§ãã¢ããªã±ãŒã·ã§ã³å šäœãäžæ°ãããŸãïŒ
:root {
--van-primary-color: #1989fa; /* ã¡ã€ã³ã«ã©ãŒ - ããªãã®ãã©ã³ãã«ã©ãŒ */
--van-success-color: #07c160; /* æåè² - ç·è±ã */
--van-danger-color: #ee0a24; /* å±éºè² - èŠåã®èµ€ */
--van-warning-color: #ff976a; /* èŠåè² - æž©ãããªã¬ã³ãž */
--van-text-color: #323233; /* ããã¹ãè² - æ·±ãé» */
--van-active-color: #f2f3f5; /* ã¢ã¯ãã£ãè² - æ·¡ãã°ã¬ãŒ */
--van-active-opacity: 0.7; /* ã¢ã¯ãã£ãéæåºŠ */
--van-disabled-opacity: 0.5; /* ç¡å¹éæåºŠ */
--van-background-color: #f7f8fa; /* èæ¯è² - ãããããªçœ */
--van-background-color-light: #fafafa; /* æããèæ¯è² */
}Less倿°ã®ã«ã¹ã¿ãã€ãº - ãã匷åãªã«ã¹ã¿ãã€ãºæ©èœ â
Lessã䜿çšããŠããå Žåã倿°ãéããŠãã詳现ãªã«ã¹ã¿ãã€ãºãå¯èœã§ãïŒ
@primary-color: #1989fa; // ã¡ã€ã³ã«ã©ãŒ
@success-color: #07c160; // æåè²
@danger-color: #ee0a24; // å±éºè²
@warning-color: #ff976a; // èŠåè²
@text-color: #323233; // ããã¹ãè²
@border-color: #ebedf0; // ããŒããŒè²
@active-color: #f2f3f5; // ã¢ã¯ãã£ãè²
@background-color: #f7f8fa; // èæ¯è²
@background-color-light: #fafafa; // æããèæ¯è²ð± ã¢ãã€ã«ãããã° - éçºãããç°¡åã« â
ãã¹ã¯ãããã§ã®ãããã° - ã¿ããæäœã®ã·ãã¥ã¬ãŒã·ã§ã³ â
æ¯åã¹ããŒããã©ã³ãæã¡äžããå¿ èŠã¯ãããŸããïŒãã¹ã¯ãããã§ã¢ãã€ã«ã®ã¿ããæäœãã·ãã¥ã¬ãŒãã§ããŸãïŒ
@vant/touch-emulatorã®ã€ã³ã¹ããŒã«ïŒ
npm install @vant/touch-emulator -Dãšãã¥ã¬ãŒã¿ãŒã®å°å ¥ïŒ
import '@vant/touch-emulator'ð±ïž éæ³ã®å¹æïŒããã§ããŠã¹ã䜿ã£ãŠæã®ã¿ãããã¹ã¯ã€ããªã©ã®æäœãã·ãã¥ã¬ãŒãã§ããŸãïŒ
宿©ãããã° - å®éã®ããã€ã¹ã§ãã¹ã â
å®éã®ããã€ã¹ã§å¹æãèŠããã§ããïŒ3ã¹ãããã§å®äºã§ãïŒ
- ã¹ããŒããã©ã³ãšã³ã³ãã¥ãŒã¿ãŒãåããããã¯ãŒã¯ã«æ¥ç¶ãããŠããããšãç¢ºèª ð¶
- éçºãµãŒããŒãèµ·å ð
- ã¹ããŒããã©ã³ã®ãã©ãŠã¶ã§ã³ã³ãã¥ãŒã¿ãŒã®IPã¢ãã¬ã¹ã«ã¢ã¯ã»ã¹ ð±
ð¡ å°æïŒéåžžãéçºãµãŒããŒã¯ http://192.168.1.100:3000 ã®ãããªã¢ãã¬ã¹ã衚瀺ããŸããã¹ããŒããã©ã³ã®ãã©ãŠã¶ã«ãã®ãŸãŸå
¥åããã ãã§ãïŒ
ð§ TypeScriptãµããŒã - åå®å šãéçºãå®å¿ â
Vantã®TypeScriptãµããŒãã¯å®ç§ã§ã远å ã®èšå®ãªãã§ãã®ãŸãŸäœ¿çšã§ããŸãïŒ
import { Button } from 'vant'
import type { ButtonType } from 'vant'
const buttonType: ButtonType = 'primary' // å®ç§ãªåãã³ãïŒâš TypeScriptã®å©ç¹ïŒ
- ð¡ïž ã³ã³ãã€ã«æã®ãšã©ãŒãã§ãã¯
- ð¡ ã€ã³ããªãžã§ã³ããªã³ãŒããã³ã
- ð ããè¯ãã³ãŒãã®å¯èªæ§
- ð ããé«ãéçºå¹ç
ð åœéå - ããªãã®ã¢ããªã±ãŒã·ã§ã³ãäžçãž â
èšèªããã¯ã®å°å ¥ - 1è¡ã®ã³ãŒãã§å€èšèªãµããŒã â
import { Locale } from 'vant'
import enUS from 'vant/es/locale/lang/en-US'
Locale.use('en-US', enUS) // è±èªã«åãæ¿ããµããŒãèšèª - äžçã®äž»èŠåžå Žãã«ã㌠â
Vantã¯30以äžã®èšèªããµããŒãããŠããŸãã以äžãå«ã¿ãŸãïŒ
ð ã¢ãžã¢å°åïŒ
- ç°¡äœåäžåœèª (zh-CN) ðšð³
- ç¹äœåäžåœèª (zh-TW) ð¹ðŒ
- æ¥æ¬èª (ja-JP) ð¯ðµ
- éåœèª (ko-KR) ð°ð·
ð æ¬§ç±³å°åïŒ
- è±èª (en-US) ðºðž
- ãã€ãèª (de-DE) ð©ðª
- ãã©ã³ã¹èª (fr-FR) ð«ð·
- ã¹ãã€ã³èª (es-ES) ðªðž
â¡ ããã©ãŒãã³ã¹æé©å - ããªãã®ã¢ããªã±ãŒã·ã§ã³ãé«éå â
ãªã³ããã³ãå°å ¥ - å¿ èŠãªãã®ã ã â
䜿çšããã³ã³ããŒãã³ãã®ã¿ãå°å ¥ããŠãã¢ããªã±ãŒã·ã§ã³ã軜éåããŸãïŒ
import { Button, Cell } from 'vant' // å¿
èŠãªã³ã³ããŒãã³ãã®ã¿ãå°å
¥ð 广æ¯èŒïŒ
- å®å šå°å ¥ïŒ~200KB
- ãªã³ããã³ãå°å ¥ïŒ~20KBïŒãã䜿ãããã³ã³ããŒãã³ãã®ã¿å°å ¥ïŒ
- ãµã€ãºåæžïŒ90%ïŒ
ç»åã®é å»¶èªã¿èŸŒã¿ - ç»åã®èªã¿èŸŒã¿ããšã¬ã¬ã³ãã«åŠç â
Lazyloadãã£ã¬ã¯ãã£ãã䜿çšããŠãç»åãå¿ èŠãªæã ãèªã¿èŸŒãããã«ããŸãïŒ
import { Lazyload } from 'vant'
app.use(Lazyload)<template>
<img v-lazy="imageUrl" /> <!-- ç»åã¯ãã¥ãŒããŒãã«å
¥ã£ãæã«ã®ã¿èªã¿èŸŒãŸããŸã -->
</template>ð ããã©ãŒãã³ã¹åäžïŒ
- åæèªã¿èŸŒã¿æéã®åæž
- ãŠãŒã¶ãŒã®ããŒã¿éä¿¡éã®ç¯çŽ
- ãŠãŒã¶ãŒäœéšã®åäž
ð åŠç¿ãã¹ - åå¿è ããå°éå®¶ãžã®é²åã®é â
ç¬¬äžæ®µéïŒåºç€å ¥é ð â
- åºæ¬ã³ã³ããŒãã³ãã®ç¿åŸïŒButtonãCellãIconïŒ
- ã¬ã€ã¢ãŠãã³ã³ããŒãã³ãã®ãã¹ã¿ãŒïŒRowãColãSpaceïŒ
- ãã©ãŒã ã³ã³ããŒãã³ãã®åŠç¿ïŒFieldãCheckboxãRadioïŒ
ç¬¬äºæ®µéïŒå¿çš ð â
- ããã²ãŒã·ã§ã³ã³ã³ããŒãã³ãã®ãã¹ã¿ãŒïŒNavBarãTabbarãTabïŒ
- ãã£ãŒãããã¯ã³ã³ããŒãã³ãã®åŠç¿ïŒDialogãToastãLoadingïŒ
- ããžãã¹ã³ã³ããŒãã³ãã®ç¿çïŒListãPullRefreshãSearchïŒ
ç¬¬äžæ®µéïŒé«åºŠãªã«ã¹ã¿ãã€ãº ðš â
- ããŒãã«ã¹ã¿ãã€ãºãšã¹ã¿ã€ã«ã®äžæžã
- ã«ã¹ã¿ã ã³ã³ããŒãã³ãã®éçº
- ããã©ãŒãã³ã¹æé©åãšãã¹ããã©ã¯ãã£ã¹
ð ãŸãšã â
ã¯ã€ãã¯ã¹ã¿ãŒããå®äºããŸããïŒð ãã®ã¬ã€ããéããŠãVantã®åºæ¬çãªäœ¿ç𿹿³ããã¹ã¿ãŒããŸãããã€ã³ã¹ããŒã«èšå®ããã³ã³ããŒãã³ãå°å ¥ãããŒãã«ã¹ã¿ãã€ãºããããã©ãŒãã³ã¹æé©åãŸã§ããããã®ç¥èã¯ããªãã®ã¢ãã€ã«éçºã®åŒ·åºãªåºç€ãšãªããŸãã
åŠç¿ã¯æ®µéçãªããã»ã¹ã§ããæ¥ãã§çµæãæ±ããªãã§ãã ããããŸãåºæ¬ã³ã³ããŒãã³ãã®äœ¿çšããã¹ã¿ãŒããåŸã ã«é«åºŠãªæ©èœãæ¢æ±ããŠãã ãããèŠããŠãããŠãã ãããå®è·µã¯æè¯ã®æåž«ã§ããã³ãŒããããããæžãããšã§ãVantã®é åãããã ãã§ã¯ãªãããšã«æ°ã¥ãã§ãããïŒðª
ð é¢é£ã³ã³ãã³ã â
ãããããã«å€ãã®çŽ æŽãããã³ã³ãã³ããæ¢æ±ããŸãããïŒ
- ð¯ ãã¹ããã©ã¯ãã£ã¹ - ãšã³ã¿ãŒãã©ã€ãºçŽéçºçµéšãåŠã¶
- ð Vue3 ã€ã³ãã°ã¬ãŒã·ã§ã³ - ææ°ã®Vue3ãšã³ã·ã¹ãã ãåãå ¥ãã
- ð TypeScript ã¬ã€ã - åå®å šãéçºãå®å¿
- ðš ããŒãã«ã¹ã¿ãã€ãº - ç¬èªã®ããžã¥ã¢ã«äœéšãåµãåºã
- â¡ ããã©ãŒãã³ã¹æé©å - ããªãã®ã¢ããªã±ãŒã·ã§ã³ã皲劻ã®ããã«é«éå
- ð± ã¢ãã€ã«å¯Ÿå¿ - ããããããã€ã¹ã«å®ç§ã«å¯Ÿå¿
- ð¯ ãã¶ã€ã³èŠç¯ - ãã¶ã€ã³ååã«åŸããåªããäœéšãåµãåºã
- ð Vant 4 - ææ°ããŒãžã§ã³ãæ©èœãããã«åŒ·å
- ðŠ Vant Weapp - ããã¢ããªéçºã®é Œããã婿
- â ãããã質å - éçºäžã®é£åã解決
- ð ãåãåãã - åé¡ãçºçããŸãããïŒãã€ã§ããµããŒãããããŸã