https://vuejs.org/guide/essentials/component-basics.html
App.vue
npm run serve
명령어를 진행 했을 때 나온 화면의 대부분이 HelloWorld.vue// App.vue
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<template>
<div>
<h1>This is Component</h1>
</div>
</template>
<script>
export default {
name: 'MyComponent',
}
</script>
<style>
</style>
import {instance name} from {위치}
@
는 src의 shortcut.vue
생략 가능// App.vue
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
// 불러오기
import MyComponent from '@/components/MyComponent.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
import MyComponent from '@/components/MyComponent.vue'
export default {
name: 'App',
components: {
HelloWorld,
MyComponent
}
}
</script>
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<MyComponent/>
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
// MyComponent.vue
<template>
<div class="border">
<h1>This is my Component</h1>
</div>
</template>
<script>
export default {
name: 'MyComponent',
}
</script>
<style>
.border {
border: solid;
}
</style>
// MyChild.vue
<template>
<div>
<h3>This is child component</h3>
</div>
</template>
<script>
export default {
name: 'MyChild'
}
</script>
<style>
</style>
// MyComponent.vue
<template>
<div class="border">
<h1>This is my Component</h1>
<MyChild/>
</div>
</template>
<script>
import MyChild from '@/components/MyChild.vue'
export default {
name: 'MyComponent',
components: {
MyChild,
}
}
</script>
<style>
.border {
border: solid;
}
</style>
// MyComponent.vue
<template>
<div class="border">
<h1>This is my Component</h1>
<MyChild/>
<MyChild/>
<MyChild/>
</div>
</template>
// App.vue
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<MyComponent/>
<MyComponent/>
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
scoped
- 해당 컴포넌트에만 스타일 적용<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
https://github.com/mjieun0956/TIL/tree/master/Vue/05.%20Vue%20component/vue-cli