vue父子组件传值
1.父组件给子组件传值用props属性实现
-
<city-list :cities='cities' :hot='hotCities' :letter='letter'></city-list>
子组件通过props属性来接收
-
export default {
-
name:"CityList",
-
props:{
-
hot:Array,
-
cities:Object,
-
letter:String
-
}
-
}
2.子组件给父组件传值 ,通过$emit()实现
-
handleLetterClick(e){
-
//把字母传给父亲,父亲再给List
-
this.$emit('change',e.target.innerText)
-
}
-
<city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
-
handleLetterChange(letter){
-
this.letter=letter
-
}