Yêu cầu thg 4 16, 2019 1:10 CH 423 0 1
  • 423 0 1
0

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

Chia sẻ
  • 423 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 CÂU TRẢ LỜI


Đã trả lời thg 4 17, 2019 3:48 SA
Đã được chấp nhận
+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 á.

Chia sẻ
Avatar Duc Son @stone89son
thg 4 19, 2019 12:38 CH

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

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí