前端写页面,我们经常需要从A页面传值给B页面,比如下面的场景
下面来实现下:
A页面——My.vue
在去“order”页面的方法中通过params传值current=1
<template>
<div id="app">
...
<div @click="gotoWaitpay">
<img src="../../static/images/order_icon1.png"
alt />
<span>待支付</span>
</div>
...
</div>
</template>
<script>
export default {
data () {
return {
}
},
methods: {
gotoWaitpay () {
this.$router.push({
name: 'Order',
params: {
current: 1
}
})
},
},
}
</script>
B页面——Order.vue
在B页面通过 this.$http://route.params.xxx接收A页面传来的值
<template>
...
</template>
<script>
export default {
data () {
return {
swiper_current: 0,
tabbar_current: 0,
}
},
methods: {
},
created () {
if (this.$route.params.current) {
this.tabbar_current= this.$route.params.current
this.swiper_current = this.$route.params.current
} else {
}
}
}
</script>