728x90
How to import components outside root path in vue
원하는 컴포넌트를 최상위 컴포넌트에 연결하는 방법
Create a component
컴포넌트 만들기란 하나의 vue파일을 만드는 것 ( 예 Fruits.vue )
// Fruits.vue
<template>
<section>
<h1>Fruits</h1>
<ul>
<li
v-for="fruit in fruits"
:key="fruit">
{{ fruit }}
</li>
</ul>
</section>
</template>
<script>
export default {
data() {
return {
fruits: [
'Apple', 'Banana', 'Cherry'
]
}
}
}
</script>
Import Component
components폴더 내에 있는 Fruits.vue파일을 연결한다.
<script>
import Fruits from '~/components/Fruits'
</script>
<Script>
Components옵션을 객체데이터로 선언한다.
<script>
import Fruits from '~/components/Fruits.vue'
export default {
components: {
Fruits
}
}
</script>
<Template>
Components의 이름을 빈 태그로 사용한다.
<template>
<Fruits />
</template>
728x90
'FE' 카테고리의 다른 글
Vue.js Watch/Computed Caching - Computed VS Methods (0) | 2021.12.11 |
---|---|
Vue.js 템플릿 기본 문법 - 보간법, 디렉티브(동적 전달인자) (0) | 2021.12.11 |
Vue.js설치방법과 webpack template에서 사용법 (0) | 2021.12.06 |
Vue.js ESLint 문법검사 구성 (0) | 2021.12.06 |
NPX degit과 git clone의 차이점 (0) | 2021.12.05 |