微信小程序里url里有变量的时候怎么写?

发布于 6 年前作者 bfu4068 次浏览最后编辑 6 年前来自 issues

其中“restaurantId”和“shopId”都是在js中定义的变量,如何形成正确的url地址。求大神指导!

4 回复
cmao
cmao1 楼6 年前

1 使用字符串拼接:

wx.navigateTo({
  path: 'restaurantId/shop/shop?shopId=' + shop_id
})

2 使用模板字符串:

wx.navigateTo({
  path: `restaurantId/shop/shop?shopId=${shop_id}`
})
changyang
changyang2 楼6 年前

你这样的格式需要用反引号。`xxxxx${aaa}`

wei88
wei883 楼6 年前

url: ‘…/restaurantId/shop/shop?shopId=’ . this.shop_id

juandai
juandai4 楼4 年前

url: ‘xxxx?shopId=’ + shop_id