一、父級和字組件之間的數據傳遞
1.父子傳值
第一步: 在父元素中綁定一個參數 我這里的是::good ="item"
<goods :index='index' :good ="item"></goods>
第二步: 在子元素中接受,使用props接收。
props: {
good:{
type:Object
}
}
2.子向父傳值
第一步: 在子組件中觸發
self.$emit('selectCity',self.city_name)
我這里並沒有傳值,如果需要傳值,就:self.$emit('selectCity', '你要傳的值').
第二步: 在父元素監聽事件 selectCity事件
<selectCity v-on:selectCity='selectCity'></selectCity>
傳參的直接在updates (參數) { }
3.同級之間的參數傳遞
兩種方式
1.query傳參,或者params傳參
使用 this.$router.push({path: '/', query: {參數名: '參數值'})
this.$router.push({name: '/', params: {參數名: '參數值'})
注意: 使用params時不能使用path
接收: var a = this.$route.query.參數名
var b = this.$route.params.參數名
2.sessionStore傳參
觸發
監聽