父向子組件傳遞
在父組件里子組件的模板里寫上要傳遞的key和value
<child key='value'></child> 或者 <child :key='value'></child> 如果是通過冒號綁定, value需要先在data里定義
子組件內添加props:['key'] 進行接收 props與data同級
子向父傳遞
子組件的方法內通過 this.$emit('name',value);進行傳值
父組件通過@name=fn進行接收 <child @key='fn'></child> fn(msg) 函數里的msg就是子組件傳遞過來的數據
路由傳參
<router-link :to="{name:'hello',params:{mes:message}}">頁面1</router-link> //hello為路由的name
編程式導航 使用 this.$router.push({name:'hello',params:{mes:this.message}})
接收參數使用 this.$route.params.message
query形式 參數會顯示在地址欄 用法相同,將params改為query
@click="fn($enent,args)" 傳遞enent參數給方法
this.$forceUpdate() vue數據更新后頁面手動渲染
