navigateToPage1() { this.$router.push('/dormitorySelectionAdmin/0') this.load() },怎么设置先跳转再加载页面
时间: 2024-05-13 16:14:49 浏览: 15
可以将加载页面的代码放在路由跳转之后执行的回调函数中,例如:
```
navigateToPage1() {
this.$router.push('/dormitorySelectionAdmin/0', () => {
this.load();
});
},
```
这样,在路由跳转完成后才会执行 `this.load()` 方法。注意,这种方式只适用于使用 `vue-router` 的情况。如果你使用其他的路由库,可能需要使用不同的方法来实现。
相关问题
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('/user/login');无法跳转
这问题可能因为以下原因导致:
1. `$router` 对象没有正确初始化或没有正确引入。你可以在代码中打印 `$router` 对象来检查它是否被正确初始化。
2. 路由配置中没有正确配置路由。你可以在路由配置文件中检查路由是否正确配置。
3. `this` 指针没有正确引用到组件实例。你可以在代码中打印 `this` 对象来检查它是否正确引用到组件实例。
4. 在使用 `$router.push()` 之前,需要先使用 `this.$router.onReady()` 确保 `router` 已经准备就绪。你可以在代码中添加 `this.$router.onReady(() => { this.$router.push('/user/login') })` 来解决问题。
如果你仍然无法解决问题,可以提供更多的代码和错误信息,以便我更好地帮助你解决问题。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![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)