ð°åå¿è ããã³ããšã³ãžãã¢ã®ããã® Vue3 åŠç¿ãããŒ
ãã®ã¹ã¯ã©ããã«ã€ããŠ
ðäœæçç±
2022幎3æçŸåšãVueãåŠç¿ãã¯ãããŸããããVue3ã®æ å ±âŠå°ãªãïŒïŒãšæããã®ã§ãåŠç¿ã¡ã¢ãšããŠæŽ»çšããªããæŽæ°ããããšã«ããŸããã
ð°ãããªäººã«ãããã
ðãé¡ã
- å·çè ããã®ããŒð°ð©âð»ã§ã
- ãã®ã¹ã¯ã©ãããæ©ã«Vue3ãå°å ¥ããå Žåã¯ãä»ã®æ å ±ãšç §ããåãããäžã§ã掻çšãã ããïŒ
- ãã£ãšè¯ãåŠç¿æ¹æ³ãããã°ããæ°è»œã«ã³ã¡ã³ãããã ãããšãããããã§ãðââ
ãããããVue.jsãã£ãŠäœïŒð€
Vue.js å
¬åŒãµã€ãããã³ãããŒãžããåŒçš
Vue.js(ãŽã¥ãŒã»ãžã§ã€ãšã¹)ã¯ã2014幎2æã«åçãªãªãŒã¹ããããWebUI[1]ããæ§ç¯ããããã«éçºããããJavaScriptãã¬ãŒã ã¯ãŒã¯[2]ãã§ãã誰ã§ã䜿çšã§ãããMITã©ã€ã»ã³ã¹[3]ãã®ãœãŒã¹ã³ãŒãã§ãã
Vue.jsã®ç¹åŸŽ
ð¡åãããããïŒ
æ§é ãã·ã³ãã«ãªã®ã§ãHTML/CSS/JavaScriptã®ç¥èãããã°ããã«å°å ¥ã§ããïŒ
ð€²äŸ¿å©ïŒ
1床äœæããããŒãã¯ãä»ã®ããŒãžãªã©ã§ãåæ ã§ããŠäŸ¿å©ïŒ
ðDOMæäœãç°¡åã«ã§ããïŒ
åºæ¬çã«HTMLãæžãæããããã§DOM[4]æäœãã§ããŠãHTMLã®ããèŠçŽ ã®é衚瀺ãªã©ãç°¡åã«èšå®ã§ããïŒ
ð°ãã£ãšè©³ãã
以äžã®å
¬åŒãµã€ãã確èªããŠãã ããã
ãJavaScriptããjQueryããVue.jsããšãèããã©ãã©ãéãã®ïŒð€
æ¯èŒäŸ
- â JavaScriptïŒHTMLãåçã«å€æŽã§ããããã°ã©ãã³ã°èšèªãèšè¿°ãé·ãã
- â¡jQueryïŒJavaScriptã®æžãæ¹ãçãããŠãããä»çµã¿(JavaScriptã©ã€ãã©ãª)ãâ ããçãã
- â¢Vue.jsïŒå°çšã«èšè¿°ããå 容ã«åãããŠãã¡ã€ã«ãæäœããŠãããä»çµã¿(JavaScriptãã¬ãŒã ã¯ãŒã¯)ãâ â¡ããã¹ãããªã
ð°ããããèšäº
*èšäºå ã®Vueã³ãŒãã¯Vue2ãªã®ã§æ³šæãããReactããšæ¯èŒãããŠããã©ãã©ãéãã®ïŒð€
ð°ããããèšäº
ãVue3ãã®ã3ãã£ãŠäœïŒð€
Vue.jsã®ããŒãžã§ã³ã§ãã2020幎9æã«Vue3ãæ£åŒãªãªãŒã¹ãããŸããã
2022幎3ææç¹ã§ã¯Vue2ã«é¢ããæ
å ±ã®æ¹ãå€ãããŸãèšè¿°æ¹æ³ãå°ãç°ãªãã®ã§ããã³ããããŠãäžæããããªãïŒè«ŠãããâŠðããšããããããã®å£ã«åœãããã¡ã§ãã
ãã®ã¹ã¯ã©ããã§å°ãã§ã解æ¶ãããã°å¬ããã§ãã
ð° Vue2ããVue3ãžã®å€æŽç¹
*Vue3ã䜿ãã®ã§ããã°èªãå¿ èŠã¯ãããŸããã-
ð°ç°¡åã«èšãã°ããã¿ã³ããã©ãŒã ãªã©ã®ãæäœç»é¢ãã®ããšãããããèšäºïŒãŠãŒã¶ã€ã³ã¿ãŒãã§ãŒã¹ (user interface)ãšã¯ïœITçšèªèŸå ž â©ïž
-
ð°ç°¡åã«èšãã°ãã·ã¹ãã éçºã楜ã«è¡ããããã«çšæããããããã°ã©ã ã®ã²ãªåœ¢ãã®ããšãããããèšäºïŒãã¬ãŒã ã¯ãŒã¯ (framework)ãšã¯ïœITçšèªèŸå ž â©ïž
-
ð°ç°¡åã«èšãã°ããèäœæš©è¡šç€ºãããã°èª°ã§ã䜿ã£ãŠãOKãªèäœç©ããMITã©ã€ã»ã³ã¹ãšã¯ïœITçšèªèŸå ž â©ïž
-
ð°ç°¡åã«èšãã°ãWebãæ§ç¯ããããã®ãããŒã¿ãã€ãªããä»çµã¿ãã®ããšãããããèšäºïŒDOM, ä»®æ³DOMãšã¯çµå±äœãã®ãïŒâZenn â©ïž
ð¡åŠã¶åã®æ³šæç¹
æå¿ã®èšäºã ãã§æžãŸããŠããŸããã¡ã§ãããå
¬åŒã®ããã¥ã¡ã³ãã¯çŸããŒãžã§ã³ã®å
容ãèšèŒããŠããå¯èœæ§ãé«ããä¿¡é Œæ§ããããŸãã
ãŸããå
¬åŒããã¥ã¡ã³ãã¯æãã·ã³ãã«ã«äŸãèšèŒãããŠããããšãå€ãã®ã§ãå
¬åŒããã¥ã¡ã³ãã®ã³ãŒããç解ããæ¹ãè¿éã«ãªããããã§ãã
å ¬åŒããã¥ã¡ã³ãã®æå³ãåãããªããã°ãæå¿ã®èšäºã確èªããâŠãšããæµãã®ã»ãããåå¿è ð°ã«ã¯ããããã§ãã
Vue.js å ¬åŒããã¥ã¡ã³ã
ãLesson01ãåŠç¿ç°å¢ã®æ§ç¯
CodePenã䜿ã£ãŠããã³ãã³ãŒãã£ã³ã°ç°å¢ãäœã
01.
CodePenã®ç»é¢
CodePenã¯ãã©ãŠã¶äžã§ããã³ãã³ãŒãã£ã³ã°ãã§ãããµãŒãã¹ã§ããVScodeã§èšè¿°ããŠãããŒã«ã«ãµãŒããŒãç«ã¡äžããŠãè¯ãã®ã§ããããŸãVue3ãè©Šãã®ã§ããã°CodePenãªã©ã®ãµãŒãã¹äžã§ç¢ºãããã®ãäžçªæ©ãã§ãã
CodePen
02.CDNã§Vue3ãåã蟌ã
â HTMLã®é圢ãäœæãã
HTMLã®æ¬ã§'!'ããŒãå
¥åããŠ'tab'ããŒãæŒããŠé圢ã衚瀺ããŠãã ããã
head
å
ã«CDNããã±ãŒãžãåã蟌ã
â¡ä»¥äžã®ããŒãžã«è¡šèšãããŠããscript
ã³ãŒããã³ããŒããŠãã ããã
ã³ãŒãã¯ä»¥äžã®ãããªãã®ã«ãªããŸã(èŠå
¬åŒãµã€ã確èª)
<script src="https://unpkg.com/vue@next"></script>
ã³ããŒããããâ ã®head
å
ã«ããŒã¹ãããŠãã ããã
03.Vue.jsãåäœããã確èªãã
ãã©ãŠã¶ç»é¢ã«ãHello Vue!!ãã衚瀺ããããã·ã³ãã«ãªã³ãŒãã§æ§ç¯ããŸãããã
å
¬åŒã玹ä»ããŠãã以äžã®ã³ãŒããã³ããŒããŠã確èªããŠãã ããã
以äžã®ç»åã®ããã«Hello Vue!!
ãšè¡šèšãããã°OKã§ãã
â³ããã§åŠç¿ç°å¢ã®æ§ç¯ã¯å®äºã§ãïŒæ¬¡ã®ã¹ã¯ã©ããããVue3ãæ¬æ Œçã«è§ŠããŸãã
ãLesson02ã宣èšçã¬ã³ããªã³ã°ã®ãã¹ã
ð°ã宣èšçã¬ã³ããªã³ã°ãã«ã€ããŠã®åèèšäº
åŠç¿æºå
以äžã®3ã€ãçšæããŸãããã
â
ãLesson01ãã§åäœç¢ºèªããCodePenã®HTMLé圢ãéã
CodePenã¢ã«ãŠã³ãç»é²ããã°äŸ¿å©ã§ãã
â
å
¬åŒããã¥ã¡ã³ãã¯ããã«ããŒãžãéã
åæ©çãªè§£èª¬ãèšèŒãããŠããã®ã§ããŸãã¯ãã®ããã¥ã¡ã³ãã®å
容ãç解ããããšããå§ããŸãã
ãã ãå
ãè±èªãªã®ã§ãã¡ãã£ãšåããã¥ããã§ãã
â ãð°ããããã解説åç»ãéã
äžèšã®ãããã°ã©ãã³ã°æ宀 Kikuãã£ã³ãã«ã解説åç»ãèŠãªãããã£ãŠã¿ããšãéåžžã«åããããããšæããŸãïŒç§ãå©ããããŸããã
ðããã§ã¯åŠç¿ã¹ã¿ãŒãã§ãïŒ
宣èšçã¬ã³ããªã³ã°ãã³ãããã
01.å ¬åŒããã¥ã¡ã³ãã®å ¬åŒããã¥ã¡ã³ãã®å®£èšçã¬ã³ããªã³ã°ã«èšèŒãããHTML/JSãã³ããŒããCodePenã«èšè¿°ããŠãã ããã以äžã®ããã«ãªãã°æåã§ãã
衚瀺ãããŠãããCounter: 0ããæéçµéã§åããã®ãç®æšã§ãã
å
¬åŒããã¥ã¡ã³ãã«èšèŒãããŠãã以äžã®ã³ãŒã(èŠå
¬åŒããã¥ã¡ã³ãåç
§)ãJSã«ä»ãå ããŠãã ããã
const Counter = {
data() {
return {
counter: 0
}
+ },
+ mounted() {
+ setInterval(() => {
+ this.counter++
+ }, 1000)
+ }
}
Vue.createApp(Counter).mount('#counter')
以äžã®ããã«ãªãã°OKã§ãã