전체 글 552

js 배열의 index 값을 객체의 키로 변경하는 방법 [] -> {}

아래와 같은 배열이 있습니다. 0: {id: 'prdctCd', value: 'USKRW'} 1: {id: 'realCode', value: 'USDKRW300'} length: 2 배열의 키가 0 , 1 숫자로 되어 있는것을 객체로 변경해야 할때가 있습니다. prdctCd: {id:'prdctCd', value:'USKRW'}, realCode: {id:'realCode', value:'USDKRW300'} 이렇게 변경하는 이유는 배열의 0 으로 접근하는 것보다는 키로 접근하는게 가독성이 좋습니다. 1차원 배열 변경 방법 const tmp = [ {id:'prdctCd', value:'USKRW'}, {id:'realCode', value:'USDKRW300'} ]; const object = tmp...

프로그래밍/Js 2023.06.20

vue3 composition api 에서 다른 컴포넌트 함수 호출

composition api 의 send.vue (자식 컴포넌트) 주의) defineExpose 없으면 작동하지 않습니다. 참고 : https://stackoverflow.com/questions/72223441/call-a-function-from-another-component-using-composition-api Call a function from another component using composition API Below is a code for a header and a body (different components). How do you call the continue function of the component 2 and pass a parameter when you are in..

프로그래밍/Js 2023.06.13

vue3 갑자기 Error: Cannot find module 'vue/compiler-sfc' 발생시

vue3 에서 어제까지 잘되던 부분이 오늘 갑자기 아래 오류를 발생한다. (macos) Error: Cannot find module 'vue/compiler-sfc' 해결방법 package.json 에 "@vue/compiler-sfc": "^3.2.13" { "name": "vue03", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, "dependencies": { "axios": "^0.27.2", "core-js": "^3.8.3", "iconv-lite": "^0.6.3",..

프로그래밍/Js 2023.05.19

intellij java11 + spring boot + 웹소켓 서버 (WebSocket Server) 구축

프로젝트 폴더(untitled1) 우측 마우스 클릭 Add Framework Supprot... 클릭 WebServices 체크 Apache Axis 변경 Spring MVC 체크 src/main/java 에서 패키지 생성 (kdh) .java Class 추가 ChatServer package kdh; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; import java.util.HashMap; import java.util.Map; @ServerEndpoint("/ws") public class ChatServer { private Map usernames = new Has..

vue options API vuex Store modules 사용법

vuex store 사용시 많은 양의 데이터를 하나의 store 파일에서 작업하기엔 벅차 store 모듈로 쪼개는 방법을 알아보고자 합니다. store 디렉토리 구조 store/modules/Counter.js /modules/moduleA.js index.js index.js import { createStore } from 'vuex' import { Counter } from './modules/Counter' import { moduleA } from './modules/moduleA' export default createStore({ mudules: { Counter, moduleA }, //기존 저장소 }); moduleA.js export const moduleA = { namespaced..

프로그래밍/Js 2023.04.13

vue3 options API 사용시 watch 사용법

vue3 에서 options API 사용할때 watch 사용방법을 알아보도록 하겠습니다. options API 에서는 setup() 할수 안에서 아래와 같이 watch 사용합니다. 첫번째 방법 import { useStore } from 'vuex'; export default { ... ... setup() { const store = useStore(); store.watch(_=>store.getters.afterLogin, _=>{ console.log(store.getters.afterLogin); }); store.watch(_=>store.getters.ofprInfo, _=>{ console.log(store.getters.ofprInfo); }, {deep:true}); }, mounte..

프로그래밍/Js 2023.04.12

재귀함수 (꼬리물기 최적화) 샘플

재귀함수를 꼬리물기 최적화 재귀함수로 변경한다. why. 현시점에서 재귀함수는 스택오버플로우를 발생하기 때문에 꼬리물기 최적화 재귀함수로 변경한다. 그다음 꼬리물기 최적화된 재귀함수는 언제든지 while 문으로 변경할수 있다. 샘플 예제를 확인해보자 꼬리물기 최적화가 안된 재귀함수 ( 이유 : 연산자 + 때문에 스택 해제를 하지 못한다.) const sum = (v) => { return v > 0 ? v + sum(v-1) : 0; }; console.log(sum(5)); console.log(sum(5000000)); 꼬리물기 최적화 된 재귀함수(크롬에서는 아직까지 꼬리물기 최적화 지원이 안된다.) const sum2 = (v, hab=0) => { hab += v; return v > 0 ? su..

프로그래밍/Js 2023.04.04

ES6 클래스의 메소드를 함수호출하는 방법

클래스의 메소드를 함수를 이용하여 호출하는 방법을 알아보도록 합니다. 템플릿 메소드를 이용한것입니다. 대략 23분 참고 https://www.youtube.com/watch?v=ik7HZrEqfEA&list=PLBA53uNlbf-vuKTARH6Ka7a_Jp0OVT_AY&index=2 const SET = { stage: { max:10, } }; const Subdata = class { constructor(listener) {} notify() {} clear() { this._clear(); } }; const Stage = class extends Subdata { _clear() { console.log('_clear()'); console.log(SET.stage.max) } }; 을 아래와 ..

프로그래밍/Js 2023.03.31