国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

New Router頁(yè)面上的元件只有在手動(dòng)刷新整個(gè)頁(yè)面後才會(huì)加載
P粉986937457
P粉986937457 2024-03-29 12:20:42
0
1
528

我新增了一條新路線,並新增了過渡到新路線的動(dòng)畫。

我新增了以下程式碼,當(dāng)我點(diǎn)擊按鈕時(shí),程式碼會(huì)推送新路由(/first):

/* From the Template */
<router-view @clickedNext1="onClickTransition" v-slot="{ Component }">
    <transition name="route1" mode="out-in">
      <component :is="Component"></component>
    </transition>
  </router-view>

/* From the Script */
 methods: {
    onClickTransition() {
      this.$router.push("/first");
    },

現(xiàn)在的問題是,當(dāng)我點(diǎn)擊按鈕並呼叫「onClickTransition」方法時(shí),路由器似乎被推送得很好,但頁(yè)面是空的。只有當(dāng)我透過按 ctrl R 手動(dòng)刷新頁(yè)面時(shí)才會(huì)呈現(xiàn)元件。

我相信問題可能來自動(dòng)畫的插入,但如果我手動(dòng)刷新頁(yè)面,動(dòng)畫效果就很好。所以我不知道問題是什麼。我將非常感謝您的幫助。

這是 app.vue 的其餘程式碼:

<template>
  <router-view @clickedNext1="onClickTransition" v-slot="{ Component }">
    <transition :key="$route.fullPath" name="route1" mode="out-in">
      <component :is="Component" />
    </transition>
  </router-view>
</template>

<script>
export default {
  name: "App",
  components: {},
  data() {
    return {};
  },
  methods: {
    onClickTransition() {
      this.$router.push("/first");
    },
    leave(event) {
      event.preventDefault();
      event.returnValue = "";
    },
  },

  mounted() {
    window.addEventListener("beforeunload", this.leave);
  },

  beforeUnmount() {
    window.removeEventListener("beforeunload", this.leave);
  },
};
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #fff;
  background-color: #151515;
  position: relative;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  margin: 0px;
}

/* route transition */
.route1-enter-from {
  opacity: 0;
}
.route1-enter-active {
  transition: all 3s ease-in;
}
.route1-leave-to {
  opacity: 0;
}
.route1-leave-active {
  transition: all 3s ease-in;
}
</style>

index.js 中的程式碼部分:

import { createRouter, createWebHistory } from "vue-router";
import MainPage from "../views/MainPage.vue";
import FirstScene from "../views/FirstScene.vue";

const routes = [
  {
    path: "/",
    name: "main",
    component: MainPage,
  },
  {
    path: "/first",
    name: "first",
    component: FirstScene,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;

「onClickTransition」方法來自「PreStartPage.vue」元件,該元件是主路由「MainPage.vue」的子元件。

一旦在「PreStartPage.vue」中按一下「Next」按鈕,它就會(huì)使用this.$emit."MainPage.vue" 向「MainPage.vue」發(fā)送事件,然後使用名為「的方法接收該事件” onClickNext1”,它透過另一個(gè)this.$emit 向“App.vue”發(fā)送信號(hào)。這就是App.vue 中顯示的“@clickedNext1”的來源。

以下是「PreStartPage.vue」中的程式碼:

<script>
export default {
  name: "PreStartPage",
  methods: {
    onClickNext() {
      this.$emit("clickedNext");
    },
  },
};
</script>

這是來自「MainPage.vue」的程式碼:

<script>
import PreStartPage from "../components/PreStartPage.vue";
export default {
  name: "MainPage",
  components: { PreStartPage },
  data() {
    return { showMain: true, showPre: false };
  },
  methods: {
    toggleMain() {
      this.showMain = !this.showMain;
      this.showPre = !this.showPre;
    },
    onClickNext1() {
      this.$emit("clickedNext1");
    },
  },
};
</script>

P粉986937457
P粉986937457

全部回覆(1)
P粉469090753

嘗試像這樣修改您的程式碼:

/* From the Template */

 
  
 

設(shè)定為 $route.fullPath 的「key」屬性應(yīng)確保每當(dāng)路由變更時(shí)都能正確完成轉(zhuǎn)換。

編輯

要解決這個(gè)問題,您可以為過??渡元件添加“:enter-active-class”和“:leave-active-class”屬性,這允許您指定在過渡期間應(yīng)應(yīng)用於元素的類別過渡。

在 App.vue 元件中,您可以像這樣更新轉(zhuǎn)換元件:


  

這將確保在轉(zhuǎn)換期間將正確的類別應(yīng)用於元素,並確保元件在動(dòng)畫開始之前完全呈現(xiàn)。

有關(guān)更多信息,我應(yīng)該您訪問官方維基:https://vuejs.org/guide/built-ins/transition.html#css-based-transitions

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板