Vue組件通訊子組件傳值給父組件主要經過$emit函數
給子組件綁定一個事件this
//子組件 @事件名=‘函數’ <child @children='fn'></child> //在子組件methods選項卡中添加事件 methods:{ fn(){
//this.$emit('父組件綁定事件名',值) this.$emit(‘father’,value) } }
在父組件中給子組件標籤綁定事件spa
<father>
<!--> <child @事件名=‘函數’ </--> <child @father='father'></child> <father> //父組件methods選項卡中用定義的函數實現傳值 methods:{ //事件名(值){} father(valuue){ this.father=this.value } }