<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>์ปดํฌ๋ํธ๊ฐ ๋ฐ์ดํฐ ์ ๋ฌ</title>
</head>
<body>
<div id="app">
<child-component v-bind:propsdata="message"></child-component>
<sibling-component v-bind:propsdata="date" v-on:showmsg="printHello"></sibling-component>
</div>
<!--
๊ฐ ์ปดํฌ๋ํธ์์ ์ฌ์ฉ๋๋ ๋ณ์๋ ๋ฉ์๋๋ ๊ณ ์ ํ scope๋ฅผ ๊ฐ์ง๊ธฐ ๋๋ฌธ์ ์ผ๋ฐ ํธ์ถ ๋ฐฉ๋ฒ์ผ๋ก call ํ ์ ์์
์์ ์ปดํฌ๋ํธ -> ํ์ ์ปดํฌ๋ํธ๋ก props์ ์ด์ฉํด ๋ฐ์ดํฐ ์ ๋ฌ๋ง
ํ์ ์ปดํฌ๋ํธ -> ์์ ์ปดํฌ๋ํธ๋ event๋ฅผ ์ ๋ฌ๋ง
ํ๋ ๊ฒ์ด vue.js์์ ์ฌ์ฉํ๋ ์ปดํฌ๋ํธ๊ฐ ๋ฐ์ดํฐ ํต์ ๋ฐฉ๋ฒ์
(๋จ, ์ ํ ๋ค๋ฅธ ๋ ๋ฒจ์ด๋ ์์น์ ๋ฐ์ดํฐ ์ ๋ฌ์ eventBus๋ฅผ ์ฌ์ฉํจ)
-->
<script src="https://unpkg.com/vue" charset="utf-8"></script>
<script type="text/javascript">
Vue.component('child-component', {
props: ['propsdata'] ,
template: '<p>{{ propsdata }}</p>'
});
Vue.component('sibling-component', {
props: ['propsdata'] ,
methods: {
showMesssage: function(){
this.$emit('showmsg');
}
},
template: '<button v-on:click="showMesssage">{{ propsdata }}</button>'
});
var app = new Vue({
el : '#app' ,
data: {
message: 'hello vuejs!' ,
date: "new Date()"
},
methods: {
printHello: function(){
// console.log("hello");
this.message = new Date();
}
// ,
// printWorld: function(){
// console.log("world");
// }
}
});
</script>
</body>
</html>