1
我正在使用Advanced-Async-Components加载async component
加载后的应用程序。所以,我曾尝试下面的代码:Vue异步组件加载没有延迟,无论'延迟'参数
Index.vue
<template>
<div class="">
<Async></Async>
</div>
</template>
<script>
// async component
import LoadComp from '@/components/Loading'
import ErrorComp from '@/components/Error'
const Async =() => ({
// The component to load. Should be a Promise
component: import('@/components/Async'),
// A component to use while the async component is loading
loading: Load,
// A component to use if the load fails
error: ErrorComp,
// Delay before showing the loading component. Default: 200ms.
delay: 4000, // <--- this is not effecting the loading of component
// The error component will be displayed if a timeout is
// provided and exceeded. Default: Infinity.
timeout: 3000
})
export default {
components: {
Async
}
}
</script>
Async.vue
<template lang="html">
<div class="">
Lorem ipsum dolor sit amet, con .... very larger string/data
</div>
</template>
<script>
export default {
}
</script>
<style lang="css">
</style>
上面的代码工作正常,但它没有delay
参数的影响( Index.vue)。根据官方文档delay
是延迟显示加载组件之前。它应该在4000ms
之后加载组件,但它会立即加载。
这是怎么发生的?
除了使用setTimeout
之外,还有其他方法可以实现吗?
附加信息
我以前webpack
模板生成使用vue-cli
Vue version : ^2.4.2
感谢哥们,虽然我已经尝试过'setTimeout',只是想尝试更好的方法。但现在这只是我想的方式。只有一个问题,在延迟时间后触发setTimeout?如果上面代码中的'setTimeout'与'delay'相比要少很多,那么该怎么办呢? –
上面例子中的setTimeout函数是在延迟被指定后触发的。如果组件的加载时间少于延迟量,则加载组件将不会显示。 – thanksd