navigateToPage1() { this.$router.push('/dormitorySelectionAdmin/0') this.load() },怎么设置先跳转再load页面
时间: 2024-05-10 17:14:52 浏览: 16
你可以将路由跳转和加载数据的操作放在一个异步函数中,并使用 async/await 来确保路由跳转在数据加载完成后执行。例如:
```
async navigateToPage1() {
await this.load() // 等待数据加载完成
this.$router.push('/dormitorySelectionAdmin/0') // 跳转路由
},
```
这样可以保证在数据加载完成之前不会进行路由跳转。
相关问题
created() { if (this.$route.params.status === '0') { this.$router.push('/dormitorySelectionAdmin/0') }}在新页面怎么调用0数据
如果您想在新页面中获取参数 `status` 的值为 `0`,可以使用以下代码:
```
<template>
<div>
<p>Status: {{ status }}</p>
</div>
</template>
<script>
export default {
data() {
return {
status: null
}
},
created() {
this.status = this.$route.params.status;
// 如果 status 不为 0,跳转到 /dormitorySelectionAdmin/0 页面
if (this.status !== '0') {
this.$router.push('/dormitorySelectionAdmin/0');
}
}
}
</script>
```
在上述代码中,我们使用 `this.$route.params.status` 获取参数 `status` 的值,然后将其赋值给 `status` 变量。接着,我们判断 `status` 是否为 `0`,如果不是,就使用 `$router.push()` 方法跳转到指定页面。如果 `status` 为 `0`,则会显示当前页面的 `status` 值。
this.$router.push( /about );
this.$router.push('/about')是Vue Router中的一个方法,用于在路由之间进行导航。它会将浏览器的URL更改为指定的路径,并在路由器的历史记录中添加一个新的条目。这个方法可以接受一个字符串作为参数,表示要导航到的路径。在这个例子中,它将用户导航到名为“about”的路由。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)