Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 浏览器刷新时Meteor.userId()丢失_Javascript_Vue.js_Meteor_Meteor Accounts - Fatal编程技术网

Javascript 浏览器刷新时Meteor.userId()丢失

Javascript 浏览器刷新时Meteor.userId()丢失,javascript,vue.js,meteor,meteor-accounts,Javascript,Vue.js,Meteor,Meteor Accounts,我使用Meteor.userId()检查用户是否登录。当用户未登录(Meteor.userId()为空)和用户已登录(Meteor.userId()为非空)时,此功能运行良好。但是,如果用户登录并刷新浏览器,Meteor.userId()将丢失 社区有哪些建议可以跟踪用户是否登录?如果用户已登录且浏览器已刷新,是否应将用户重定向到登录页面?用户登录后,我是否应该将Meteor.userId()保存在本地存储中(我认为它不会工作) 更新1:主导航栏根据App.vue方法调用中的Meteor.use

我使用Meteor.userId()检查用户是否登录。当用户未登录(Meteor.userId()为空)和用户已登录(Meteor.userId()为非空)时,此功能运行良好。但是,如果用户登录并刷新浏览器,Meteor.userId()将丢失

社区有哪些建议可以跟踪用户是否登录?如果用户已登录且浏览器已刷新,是否应将用户重定向到登录页面?用户登录后,我是否应该将Meteor.userId()保存在本地存储中(我认为它不会工作)

更新1:主导航栏根据App.vue方法调用中的
Meteor.userId()
显示用户是否登录

MainNavBar.vue

<li class="nav-item d-xl-block" v-if="(this.$root.currentUserId==null)">
            <router-link class="nav-link" v-bind:to="{ name: 'register' }">Register</router-link>
          </li>
          <li class="nav-item d-xl-block" v-else>
            <a class="nav-link" href='' data-cy="logout" v-on:click="Logout()">Log out</a>
          </li>

您正在使用vue meteor吗?如果是这样的话,可能会有用。谢谢@DavidWeldon的输入。我正在使用vue meteor。我将查看您提供的链接。您好@DavidWeldon,我已经用我的分析更新了问题。我被困在如何让路由器等待用户订阅准备就绪。你有什么意见吗?
<script>
import { mapGetters } from 'vuex';
import { Meteor } from 'meteor/meteor';
export default 
{
  computed: {
    ...mapGetters('layout', ['showCart',]),
  },
  meteor: 
  {
    currentUserId()
    {
      return Meteor.userId();
    },
  },
}
</script>
router.beforeEach((to, from, next) => 
  {
    //I need to wait here till Meteor.loggingIn() returns true? 
    let loggingIn= Meteor.loggingIn();
    if (loggingIn && Meteor.userId() == null && 
      to.name ==='dashboard'
    {
      next('/login');
    }
    else 
    {
      next();
    }
  });