组件间的通信

1.父组件和子组件的传值,函数的传递式触发

子组件:

 1 <template>
 2     <div class="show-operation">
 3         
 4             <input type="text" v-model='info.name'>
 5             <input type="text" v-model='info.id'>
 6             <input type="text" v-model='info.ctime'>
 7             <input type="button" value="修改" @click="modify">
 8             <button><router-link to=/classes>cancel</router-link></button>
 9           
10             <!-- 设置函数@click=触发函数 -->
11     </div>
12 </template>
13 
14 <script>
15 export default {
16     name: 'modify',
17     data(){
18         return{
19             info:"",        
20             change:false
21         }
22     },
23     mounted(){
24         this.info = this.$route.query.per_info
25         
26     },
27 
28     
29     methods:{
30           modify(){           
31               console.log("子组件")
32               this.$emit("modify", [this.info, this.$route.query.per_info.id])
33 
34           }
35     }
36 
37 }
38 </script>
39 
40 <style>
41     .show-operation{
42         position: absolute;
43         top: 200px;
44         left: 200px;
45         background-color: red;
46         width:200px;
47         height: 200px;
48         z-index: 5;
49     }
50 </style>

父组件:

1  <transition mode="out-in">
2      <router-view @modify="modify"></router-view>                                      
3  </transition>
4    
script
{
  modify(){
  console.log('123')
}
}

2. router-link的传值方式

<router-link :to="{path:'/classes/modify', query:{per_info:item}}">修改信息</router-link>
使用 :to的动态绑定,可以指定query附加参数
 
3渲染数据后,修改页面数据不刷新的问题
使用强制刷新或者修改数据的地址和长度(内存发生变化)
或者用:key绑定唯一标识符
 
4.组件传递 动态绑定的参数 
传递动态的绑定的参数,参数改变后,父组件接收的参数也会改变,并且无需再用函数触发
 
posted @ 2021-11-18 22:22  拥有人鱼线的程序猿  阅读(26)  评论(0)    收藏  举报