学无先后,达者为师

网站首页 Vue 正文

vue3实现页面刷新

作者:鸣拙 更新时间: 2022-04-05 Vue

vue3实现页面刷新

在muuri的复杂实现中,拖动元素后,只能刷新页面才能重置回初始状态

在组件中实现页面的刷新功能

//App.vue页面
//html:
<template>
  <HelloWorld v-if="isRouterAlive"></HelloWorld>
</template>

<script>
import { provide, ref, nextTick } from "vue";
import HelloWorld from "./components/vue3/index.vue";

export default {
  name: "App",
  components: {
    HelloWorld,
  },
  setup() {
    const isRouterAlive  = ref(true);
    const reload = () => {
      isRouterAlive.value = false;
      nextTick(() => {
        isRouterAlive.value = true
      })
    }
    provide("reload", reload);
    return { isRouterAlive }
  },
};
</script>
//在需要使用的页面引用即可
const myFn = inject<any>("reload");

原文链接:https://blog.csdn.net/weixin_45939191/article/details/121556188

栏目分类
最近更新