axios定义params传参到其他页面
在使用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”,即我们传递的参数值。
原文地址: https://www.cveoy.top/t/topic/bjfn 著作权归作者所有。请勿转载和采集!