在uniapp中,页面跳转可以使用uni.navigateTo、uni.redirectTo、uni.reLaunch等方法。其中,uni.navigateTo和uni.redirectTo方法可以传递参数。

举个例子:

在A页面上,有一个按钮,点击后跳转到B页面,并传递一个参数name。

A页面代码:

<template>
  <view>
    <button @click="gotoB">跳转到B页面</button>
  </view>
</template>

<script>
export default {
  methods: {
    gotoB() {
      uni.navigateTo({
        url: '/pages/B/B?name=uniapp',
      })
    },
  },
}
</script>

B页面代码:

<template>
  <view>
    <text>{{ name }}</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      name: '',
    }
  },
  onLoad(options) {
    this.name = options.name
  },
}
</script>

在B页面中,使用onLoad钩子函数获取参数name,并在页面中显示出来。

需要注意的是,在使用uni.navigateTo和uni.redirectTo方法传递参数时,url中需要带上参数名和参数值,参数名和参数值之间用等号连接,多个参数之间用&连接。例如:

url: '/pages/B/B?name=uniapp&id=123'
uniapp页面跳转如何传参

原文地址: http://www.cveoy.top/t/topic/bHif 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录