使用uniapp框架,使用函数navigateTo传参到另一个vue里,请写出代码
时间: 2024-02-15 12:02:09 浏览: 30
好的,下面是示例代码:
在A.vue中:
```vue
<template>
<view>
<!-- 点击按钮跳转到B.vue页面 -->
<button @click="gotoB">跳转到B页面</button>
</view>
</template>
<script>
export default {
methods: {
gotoB() {
uni.navigateTo({
url: '/pages/B.vue?param1=hello¶m2=world'
})
}
}
}
</script>
```
在B.vue中:
```vue
<template>
<view>
<text>{{ param1 }}</text>
<text>{{ param2 }}</text>
</view>
</template>
<script>
export default {
onLoad(options) {
// 在onLoad函数中获取传递过来的参数
console.log(options.param1) // 输出:hello
console.log(options.param2) // 输出:world
}
}
</script>
```
以上代码中,我们在A.vue中使用`uni.navigateTo`函数跳转到B.vue页面,并通过URL参数将`param1`和`param2`传递过去。在B.vue页面的`onLoad`函数中,我们可以通过`options`参数获取传递过来的参数。