‘
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>評論列表實現</title>
</head>
<body>
<div id="app">
<com2 @subshow="show"></com2>
</div>
<template id="tmp1">
<div>
<h1>這是子組件</h1>
<input type="button" value="按我" @click="myclick">
</div>
</template>
<script src="./lib/vue-2.4.0.js"></script>
<script>
var com2={
template:'#tmp1',
data() {
return {
sonmsg: { name: '小頭兒子', age: 6 },
}
},
methods:{
myclick(){
// this.$emit('parentShow')
this.$emit('subshow',this.sonmsg)
}
}
};
// 創建 Vue 實例,得到 ViewModel
var vm=new Vue({
el:'#app',
data:{},
methods:{
show(msg){
console.log("這是父組件的方法");
console.log(msg)
}
},
components:{
com2:com2
}
})
</script>
</body>
</html>
