【问题标题】:How to manually trigger routing on nuxt.js?如何在 nuxt.js 上手动触发路由?
【发布时间】:2021-07-26 23:41:01
【问题描述】:

我想在回调中登录后手动导航到主页。

  methods: {
    async userLogin() {
      var session_url = "/api/v1/authenticate";
      axios
        .post(session_url, this.login, {})
        .then(function (response) {
          console.log("Authenticated", response.data.access_token);

          window.localStorage.setItem("token", response.data.access_token);
          // Manually trigger route here.
        })
        .catch(function (error) {
          console.log("Error on Authentication", error);
        });
    },
  },

【问题讨论】:

    标签: vue.js nuxt.js vuejs3


    【解决方案1】:

    要手动触发路由,可以使用下面的代码,其中/是家乡路由。

    注意:无需导入任何内容,因为$router 是全球可用的。

    this.$router.push("/" )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-07
      • 2015-05-12
      • 1970-01-01
      • 2019-04-24
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      相关资源
      最近更新 更多