需求:点击图一购物车按钮,跳转到购物车页面
1.按钮绑定事件
<van-goods-action-icon icon="cart-o" text="购物车" bind:click="goShoppingCart" />
2.事件(要用wx.switchTab)
// 进入购物车
goShoppingCart () {
wx.switchTab({
url: `/pages/index/shoppingCart/index`
})
},
⚠️注意这个url路径要与app.json中的pagePath一样
3.在app.json中添加
"tabBar": {
"list": [{
"pagePath": "pages/index/home/index",
"text": "首页"
},{
"pagePath": "pages/index/category/index",
"text": "分类"
},{
"pagePath": "pages/index/shoppingCart/index",
"text": "购物车"
},{
"pagePath": "pages/index/me/index",
"text": "我的"
}]
},
"pages": [
"pages/index/index",
"pages/index/home/index",
"pages/index/shoppingCart/index",
"pages/index/category/index",
"pages/index/me/index"
]
⚠️这个路径是从app.json开始数的相对路径,如图