Vue: λ Œλ”λ§ ν•¨μˆ˜(createElement) λ‚΄μ—μ„œ 슬둯 이름을 지정할 수 μ—†μŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2017λ…„ 05μ›” 28일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: vuejs/vue

이 κΈ°λŠ₯은 μ–΄λ–€ 문제λ₯Ό ν•΄κ²°ν•©λ‹ˆκΉŒ?

μ•„λž˜μ™€ 같이 λ Œλ”λ§ κΈ°λŠ₯ λ‚΄μ—μ„œ 슬둯 이름을 μ§€μ •ν•©λ‹ˆλ‹€.

return createElement(rootcmp, { default: [ createElement(childCmp) ], temp: [ createElement(childCmp2) ] } );

μ œμ•ˆλœ APIλŠ” μ–΄λ–»κ²Œ μƒκ²ΌμŠ΅λ‹ˆκΉŒ?

render ν•¨μˆ˜ λ‚΄μ—μ„œ μžμ‹ μš”μ†Œλ₯Ό 생성할 λ•Œ 'default', 'temp'와 같은 슬둯 이름을 μ§€μ •ν•©λ‹ˆλ‹€.

return createElement(rootcmp, { default: [ createElement(childCmp) ], temp: [ createElement(childCmp2) ] } );

μ•„λž˜μ˜ 전체 μ½”λ“œ:

@Component({
    props:[]
})
export class TestComponent extends Widget{
    items:any[];
    render(createElement:any){
        const rootcmp = {
            template:`<div>
                Temp:<slot name="temp"></slot>
                Default:<slot></slot>
            </div>`
            , data:()=>{
                return {};
            }
        }
        const childcmp = {
            template:'<div slot="default">This is child</div>'
            , data:()=>{
                return {};
            }
        }
        const childcmp2 = {
            template:'<div slot="temp">This is child</div>'
            , data:()=>{
                return {};
            }
        }
        return createElement(rootcmp
             , { default: [ createElement(childcmp) ], temp:[ createElement(childcmp2) ]);
    }
}

μ˜ˆμƒλ˜λŠ” λ™μž‘:

<div>
      Temp:<div>This is child</div>
      Default:<div>This is child</div>
</div>

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

createElement(childcmp, { slot: 'temp' }) λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

λͺ¨λ“  3 λŒ“κΈ€

createElement(childcmp, { slot: 'temp' }) λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

@yyx990803 κ·ΈλŒ€λ‘œ 진행해야 ν•˜λŠ” 기술적인 μ΄μœ κ°€ μžˆλ‚˜μš”? 이 방법은 λŒ€κ·œλͺ¨ λ°°μΉ˜μ—μ„œ μž¬κ·€μ μœΌλ‘œ μƒμ„±λœ λ…Έλ“œλ₯Ό μ²˜λ¦¬ν•  λ•Œ 맀우 λΉ„μ‹€μš©μ μž…λ‹ˆλ‹€. 더 μž˜ν•  수 μ—†λŠ” 쒋은 μ΄μœ κ°€ μžˆλŠ”μ§€ κΆκΈˆν•©λ‹ˆλ‹€.

μ‹€μ œλ‘œ 이 createElement(childcmp, { slot: 'temp' }) λŠ” μŠ¬λ‘―μ— 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

버그 λ³΄κ³ μ„œ 생성: https://github.com/vuejs/vue/issues/11519

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰