반응형
구성 요소의 html 요소 유형 변경
그리드 시스템의 일부인 다음 Vue JS 컴포넌트가 있습니다.
<bl-column type="section" classList="col--4-12 col--6-12--m col--1-1--s">
...
</bl-column>`
위의 예시와 같이 섹션 또는 기사를 포함하는 유형 변수를 추가하여 요소의 유형을 동적으로 " " (표준)", " " 또는 "로 설정합니다.
이것은 나의 칼럼이다.Vue 파일:
<template>
<{type} :class="classList">
<slot></slot>
</{type}>
</template>
<script>
export default {
name: "Column",
props: ['classList', 'type'],
data() {
return {
classList: this.classList || '',
type: this.type || 'div',
};
}
};
</script>
이것은 분명히 동작하지 않고 에러가 발생하지만, 요소 타입을 설정하는 방법을 알 수 있습니다.render() 함수를 사용하지 않고 실행할 수 있는 방법이 있습니까?
동적 구성 요소를 렌더링하는 더 쉬운 방법이 있습니다.문서 https://vuejs.org/v2/guide/components.html#Dynamic-Components
<template>
<component :is="type" :class="classList">
<slot></slot>
</component>
</template>
<script>
export default {
name: "Column",
props: ['classList', 'type'],
data() {
return {
classList: this.classList || '',
type: this.type || 'div',
};
}
};
</script>
온라인 예: https://jsfiddle.net/fotcpyc4/
<template>
<component :is="type">
<slot />
</component>
</template>
<script>
export default {
name: 'Heading',
props: {
type: {
type: String,
default: () => 'h1',
},
},
};
</script>
언급URL : https://stackoverflow.com/questions/42228636/change-html-element-type-of-component
반응형
'itsource' 카테고리의 다른 글
복사-붙여넣기 링크가 제대로 작동하는 동안 링크가 작동하지 않음 (0) | 2022.08.27 |
---|---|
Java에서 별도의 스레드를 사용하여 메서드를 호출하려면 어떻게 해야 합니까? (0) | 2022.08.27 |
vuejs router-link가 느린 로드 경로에서 작동하지 않음 (0) | 2022.08.27 |
형식 설명서의 다른 vue 모듈에서 vue 모듈 가져오기 (0) | 2022.08.27 |
Vuex 모듈 작업에서 vue-router를 사용하는 방법 (0) | 2022.08.27 |