웹 개발/개념 정리

[WebOrder] JSON 객체로 보내고 받기

cha430 2025. 10. 28. 15:34
const editorOpen = () => {
    noticeDialogRef.value.open("에디터 제목",false,"에디터 내용")
}​

 

이런 식으로 자식의 메서드를 호출하고

 

const open = (_title:"", _isViewer: false, _content:"") => {
    consoleLog("거래처 공지 open");

    isOpen.value = true;
    title = _title;
    isViewer = _isViewer;
    contents = _content;
};

 

자식 메서드에서 매개변수를 이렇게 받을 수 있다.

 

 

 

이걸 JSON 객체로 주고 받는 방법으로 변경하게 되면

 

const editorOpen = () => {
    noticeDialogRef.value.open({
        title:"에디터 제목",
        isViewer:false,
        content:"에디터 내용"})
}
const open = (data = { title:"", isViewer: false, content:"" }) => {
    consoleLog("거래처 공지 open");

    isOpen.value = true;
    title = data.title;
    isViewer = data.isViewer;
    contents = data.content;
};

 

이렇게 된다.

 

const open = (data = { title:"", isViewer: false, content:"" }) => {

 

이건 기본값을 주고 싶을 때 쓰는 방법이고

기본값 안줘도 되면

const open = (data) => {

 

이렇게 하면 된다.

객체 변수명은 꼭 data 일 필요는 없다.