window.location.href 在 VUE 3 JS 中

window.location.href in VUE 3 JS

我没有找到这里的问题。

当我使用

return window.location.href = 'https://www.google.com';

它工作正常。 但是,如果我使用我的字符串变量。它不会 work.Reloads 返回页面。

return window.location.href = this.navigationURL;

完整代码:-

 <table class="">
   <tr
     class="cursor-pointer"
        v-for="currentView in authenticationMethodsAvailable"
          :key="currentView.id"
            >
        <td class=""> (HERE)
   **<button type= "button" @click="authenticationChoice(currentView['name'])" >**
                <img
                  class="w-12 inline-block align-middle"
                  :src="showAuthenticationIcon(currentView['gitType'])"
                 
                />
              </button>
              </td>
            </tr>
          </table>

正在触发的函数


    authenticationChoice(recieved) {
      this.$store.state.gitSourceAuthenticationChoice = recieved;

      this.$store.dispatch("gitSourceAuthenticationURL").then((response) => {
        this.navigationURL = response["oauth2_redirect"];
        console.log(this.navigationURL)
       
      });
    return this.navigationURL ;
  // return window.location.href = String(this.navigationURL);
    },

删除破坏代码的 return 并将代码移动到 then 块中,如下所示:

    authenticationChoice(recieved) {
      this.$store.state.gitSourceAuthenticationChoice = recieved;

      this.$store.dispatch("gitSourceAuthenticationURL").then((response) => {
        this.navigationURL = response["oauth2_redirect"];
        console.log(this.navigationURL)
       window.location.href = String(this.navigationURL);
      });
  
    },