飞雷神
Teleport传送门,可以将组件渲染到另一个DOM节点,在另个DOM节点做一个标记,之后将组件渲染过去。
类似于四代木金色闪光的飞雷神。
一、index.html
定义teleport渲染的DOM节点
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<div id="loading"></div> ++
</body>
二、定义teleport
<template>
<teleport to="#loading">
<div id="center">
<h2>Loading</h2>
</div>
</teleport>
</template>
<script>
export default {};
</script>
<style>
#center {
display: grid;
justify-items: center;
align-items: center;
background-color: #eee;
}
</style>
三、About.vue中使用teleport
<template>
<div class="about">
<h1>This is an about page</h1>
<loadig></loadig>
</div>
</template>
<script>
import Loadig from './components/Loading.vue'
export default {
components:{
Loadig
}
}
</script>