在使用 Axios 发送请求时,可以使用 params 选项来传递参数。假设我们要向另一个页面发送一个名为'username'的参数,可以将其包含在 params 对象中,如下所示:

axios.get('/otherPage', {
  params: {
    username: 'john'
  }
})
.then(function (response) {
  console.log(response);
})
.catch(function (error) {
  console.log(error);
});

在另一个页面,我们可以使用this.$route.query.username获取传递的参数值。例如,我们可以在 created 钩子函数中使用以下代码:

created() {
  console.log(this.$route.query.username)
}

这将输出'john',即我们传递的参数值。

Axios 传参到其他页面:使用 params 对象传递参数

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

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