|
@@ -0,0 +1,39 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <div class="box">
|
|
|
|
|
+ <h1>{{ title }}</h1>
|
|
|
|
|
+ <h1>{{ count }}</h1>
|
|
|
|
|
+ <button v-on:click="addFun">加一</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+<script>
|
|
|
|
|
+ export default {
|
|
|
|
|
+ name: 'AddControl',
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ count: 0
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ // props (属性) 用来接收父组件传递过来的数据
|
|
|
|
|
+ // 用拟人的方式描述组件间的关系 外层的为父组件 内层的为子组件
|
|
|
|
|
+ props:['title'],
|
|
|
|
|
+ methods:{
|
|
|
|
|
+ addFun(){
|
|
|
|
|
+ this.count++;
|
|
|
|
|
+ // 子组件可以调用父组件的方法 $emit
|
|
|
|
|
+ // $emit 后边为事件名称 事件名称后边为事件传递的参数
|
|
|
|
|
+ this.$emit('changeCount',this.count);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+</script>
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+ .box{
|
|
|
|
|
+ width: 300px;
|
|
|
|
|
+ height: 300px;
|
|
|
|
|
+ border:3px solid black;
|
|
|
|
|
+ margin: 0 auto;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ }
|
|
|
|
|
+</style>
|