ãã®ããã°ã®jQueryãVue.jsã«ãªãã¬ã¼ã¹ãã¦ãã
æ¥æã®å¤ã§ãããªãä»æ¥ã¯ã¡ãã£ã¨éã³ããã¦æ¼ãã¡ãã£ã¦ãã®ã§ãã£ãã¨ããã°ãä»ä¸ãã¦ã家äºè«¸ã
ããã¦é¢¨åå
¥ã£ã¦å¯ã¦ãã¾ããããã¡ã®ä¼ç¤¾ã¯å
¬ä¼æ¥ã¯ãªãã®ã§æ®éã«åºå¤ãªãã ããã
ã¾ããä»æ¥ã¯ããããéã¶ãã¨ãã§ãã¦ã¹ãã¬ã¹è§£æ¶ã«ã¯ãªã£ãããã®ä¸é¨ã«ããè¨äºè¦ç´ã®ãã¼ããVue.jsã§æ¸ãç´ãããã°ã©ãã³ã°éã³ããã¦ããã®ã§ããã
ã¡ãªã¿ã«ã½ã¼ã¹ã³ã¼ãã«ã¤ãã¦ã¯Githubã§å ¬éãã¦ãã®ã§ãã½ã¼ã¹ãèªãã人ã¯èªãã§ã¿ã¦ããããããããªãã
ChatGPTã«ãããã°ã®ããã³ãã¨ã³ãã§ä½¿ã£ã¦ãã®ããã¾ã ã«jQueryã§ã¯ã½ããµããã©ããªããç½®ãæããæ¹æ³ã¯ãªãï¼ãã¨å°ããã¨ãããVue.jsãããã©JSã§ç½®ãæããã°ããããããªãã¨è¨ãããã®ã§ãä»ãã¨ããVue.jsãåå¼·ãã¦ãã®ããã°ã®ããã³ãã¨ã³ãã®ããã°ãã¼ããç½®ãæããä½æ¥ããã¦ããã
Vue.jsã«ã¤ãã¦ã¯Udemyã§è¯ãããªè¬åº§ãæ°æ¥ã»ã¼ã«ã§1500åãããã§è²·ããã¨ãã§ããã®ã§ãããã§ãªãã¨ãã¢ããã¼ã·ã§ã³ãä¿ã£ã¦ãã¨ããã¨ããããããããããªãããã¡ãã®è¬åº§ã§ããããæ®æ®µã¯2ä¸ãããããã®ã§ã»ã¼ã«ãçã£ã¦è²·ãã®ãããã ããã
ã¨ããããè²ã ã¨å¼ã£ã¦ã¿ãããã¦èªç±èªå¨ã«ä½¿ãããªãããããã¾ã§ã¯è¦ããããããããªã¼ã¨æããVue.jsã«é¢ãã¦ã¯å¤§è¦æ¨¡ãªéçºãããããã°ãã¼ããä½ã£ããã¿ãããªå°è¦æ¨¡ãªéçºãã§ããã®ã§ãããã³ãã¨ã³ãéçºã®åå¦è ã«ã¯ãããããªã®ãããããªãã
ä»åãè¨äºè¦ç´ã®ããã°ãã¼ããä½ãã®ãã²ã¨ã¾ãvue CLIã使ã£ã¦ããã¸ã§ã¯ããä½æãã¦ã¿ã¦ä½ã£ã¦ã¿ãã®ã ãã©ãããã¤ã£ã¦ããã°è¨äºãèªã¿è¾¼ã¾ããå¾ã«åçã«DOMãæ¿å ¥ãã¦ããã¤ãªãã ãããVue.jsã§ä½ãã¨ãããvueã¯ä»®æ³DOMã使ã£ã¦é«éãªã¬ã³ããªã³ã°ãã§ããã®ã«ããã®ã¡ãªãããä½ããªããã¨ChatGPTã«ã¯è¦åãåããããã
ã¾ã¼ãéçã«ããã°è¨äºå ã«ã¿ã°ãå ¥ãããã¨ãã§ããªããã ããä»æ¹ããã¾ããã¾ããããããå ¨éå»è¨äºã®ãã¼ã¿ã«éçãªdivã¿ã°ãªããæ¼ãè¾¼ãã¨ããã®ãç¡ççãªã®ã§ãã¡ãªããã¯ãªããã©ãã¼ã¸ãå ¨é¨èªã¿è¾¼ã¾ããå¾ã«ãentry-contentã®pã¿ã°ãå ¨é¨åãåºãã¦ãããã¦æ¥æ¬èªãå«ã¾ãã¦ãpã¿ã°ã®ä¸é¨ã«Appã³ã³ãã¼ãã³ããæ¼ãè¾¼ãã§ãã£ã¦æãã ããã
ã½ã¼ã¹çã«ã¯ãããªæãã®èªã¿è¾¼ã¿æ¹ãmain.jsã§ãã£ã¦ãã
import { createApp } from 'vue' import App from './App.vue' function initializeVueApp() { const pElements = document.querySelectorAll('.entry-content p'); let inserted = false; for (let i = 0; i < pElements.length; i++) { if (pElements[i].innerText.match(/[\u30a0-\u30ff\u3040-\u309f\u3005-\u3006\u30e0-\u9fcf]+/) && !inserted) { const mountPoint = document.createElement('div'); mountPoint.id = `vue-app-mount-point`; pElements[i].parentNode.insertBefore(mountPoint, pElements[i]); createApp(App).mount(`#vue-app-mount-point`); inserted = true; // ãã¦ã³ããã¤ã³ããæ¿å ¥ãããã«ã¼ããæãã break; } } } document.addEventListener('DOMContentLoaded', initializeVueApp);
ã¾ããã·ã³ãã«ã«DOMãèªã¿è¾¼ã¿ããã£ãã¿ã¤ãã³ã°ã§mountãããã¤ã³ãã®divã¿ã°ãåçã«åãè¾¼ãã§ããã¡ãã«createAppãã¦ãã ããªãã§ããã©ãã
ãã®ããã°ã§ã¯è¨äºæä¸ã«åãè¾¼ãã§ãã¢ãã»ã³ã¹ã®åºåãåçã«DOMãæ¼ãè¾¼ãã§ãæããªã®ã§ããããVueã§ãããã®ããªã¼ã¨æããã©ããã®å¦çã¯vueã®ã¡ãªããããªãããããã©JSã«ç½®ãæããæ¹ãããã®ããªã¨æãã
ãã¨ã¯ç»é¢ã®ãµã¤ããã¼ã®æ°çè¨äºã¨ãã®ã¡ãã¥ã¼ã§ããã¨ããç»é¢ããã¼ã¯ã¢ã¼ãã¨ã©ã¤ãã¢ã¼ãã«åãæ¿ããå¦çãªãããjQueryã§åãã¦ãã®ã§ããã¡ããVue.jsãããã©JSã§ç½®ãæãã¦ãjQueryã§åãã¦ãå¦çã¯å ¨é¨ãªãã¬ã¼ã¹ãã¦ãããããããä»å¾jQueryãã©ããªãã®ãã¼ã¨ããã®ã¯åããããã©ãã¡ã¸ã£ã¼ã¢ãããã¼ãã§var4ã«ãªããããã
ããã¼ããããªã«ç¦ãããã¦ãããã®ãã¼ã£ã¦æ°ããããã©ããã£ã±ä»æã®ITã¨ã³ã¸ãã¢ã¨ãã¦ã¯ããã¡ãã£ã¨ã¢ãã³ãªéçºãè¦ãããããã
åèè¨äº
qiita.com