Asked Apr 16th, 2019 1:10 p.m. 428 0 1
  • 428 0 1
0

Vuejs option delay,timeout trong Async component không hoạt động

Share
  • 428 0 1

Vuejs: 2.6

OS: Ubuntu

Browser: Firefox 66.x

mình muốn import component timeout khoảng 3 giây , và đọc trên https://vuejs.org/v2/guide/components-dynamic-async.html

làm theo hướng dẫn , nhưng mình thấy biến timeout, và delay có vẻ không hoạt động khi mình thử tăng cao lên 30000

nhưng kết quả vẫn không thay đổi .

 const TradeHistory = () => ({
  component: import('@@/components/Exchange/TradeHistory/TradeHistory.vue'),
  delay: 200,
   timeout: 3000
 })

Vậy có cách nào có thể delay và timeout một khoảng thời gian load component không ạ ?

1 ANSWERS


Answered Apr 17th, 2019 3:48 a.m.
Accepted
+1

@stone89son Ý bạn đang hỏi về cái syntax này à:

const AsyncComponent = () => ({
  // The component to load (should be a Promise)
  component: import('./MyComponent.vue'),
  // A component to use while the async component is loading
  loading: LoadingComponent,
  // A component to use if the load fails
  error: ErrorComponent,
  // Delay before showing the loading component. Default: 200ms.
  delay: 200,
  // The error component will be displayed if a timeout is
  // provided and exceeded. Default: Infinity.
  timeout: 3000
})

Có vẻ bạn đang hiểu nhầm rồi, syntax kia (delay + timeout) là để xử lý việc hiển thị cái LoadingComponentErrorComponent thôi. Còn muốn dùng async thì cái property component bạn return một cái promise là được. Do là promise nên bạn thích set timeout bao nhiêu giây rồi mới resolve cũng được hết á.

Share
Avatar Duc Son @stone89son
Apr 19th, 2019 12:38 p.m.

thank Ban da tra loi, minh chinh lai component roi tra loi lai Ban sau.

+1
| Reply
Share
Viblo
Let's register a Viblo Account to get more interesting posts.