温馨提示×

uniapp怎么使用接口实现内容跳转

小亿
85
2024-02-21 11:52:20
栏目: 编程语言

在uniapp中,可以通过使用uni.navigateTo或uni.redirectTo方法来实现内容跳转。这两个方法都会跳转到应用中的指定页面,并可以传递参数给目标页面。

  1. 使用uni.navigateTo方法实现内容跳转:
uni.navigateTo({
  url: 'pages/targetPage',
  success: function(res) {
    console.log(res)
  },
  fail: function(err) {
    console.log(err)
  }
})
  1. 使用uni.redirectTo方法实现内容跳转:
uni.redirectTo({
  url: 'pages/targetPage',
  success: function(res) {
    console.log(res)
  },
  fail: function(err) {
    console.log(err)
  }
})

在目标页面中,可以通过uni.getStorageSync或uni.getStorage方法获取传递过来的参数:

// 目标页面中获取参数
let params = uni.getStorageSync('key')
console.log(params)

或者

uni.getStorage({
  key: 'key',
  success: function(res) {
    console.log(res.data)
  },
  fail: function(err) {
    console.log(err)
  }
})

通过以上方法,可以实现在uniapp中使用接口实现内容跳转,并且传递参数给目标页面。

0