console
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
第一次点击会在2s后显示组件,然后将该组件进行缓存,之后就直接显示该组件.
<br>
<button @click="show=!show">button</button>
<child-comp v-if="show"></child-comp>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
show: false
}
},
components: {
'child-comp': (res,rej)=> {
setTimeout(()=>{res({template: '<h1>async component</h1>'})}, 2000)
}
}
})
</script>
</body>
</html>