ContentIndex: phương thức delete()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Web Workers.

Phương thức delete() của giao diện ContentIndex hủy đăng ký một mục khỏi nội dung hiện đang được lập chỉ mục.

Note: Việc gọi delete() chỉ ảnh hưởng đến chỉ mục. Nó không xóa bất cứ thứ gì khỏi Cache.

Cú pháp

js
delete(id)

Tham số

id

Mã định danh duy nhất của nội dung đã lập chỉ mục mà bạn muốn đối tượng ContentIndex xóa.

Giá trị trả về

Trả về một Promise được giải quyết với undefined.

Ngoại lệ

Không có ngoại lệ nào được ném ra.

Ví dụ

Bên dưới là một hàm bất đồng bộ xóa một mục khỏi chỉ mục nội dung. Chúng ta nhận tham chiếu tới ServiceWorkerRegistration hiện tại, cho phép truy cập thuộc tính index và từ đó truy cập phương thức delete.

js
async function unregisterContent(article) {
  // tham chiếu registration
  const registration = await navigator.serviceWorker.ready;

  // phát hiện Content Index
  if (!registration.index) return;

  // hủy đăng ký nội dung khỏi chỉ mục
  await registration.index.delete(article.id);
}

Phương thức delete cũng có thể được dùng trong phạm vi service worker.

js
self.registration.index.delete("my-id");

Thông số kỹ thuật

Specification
Content Index
# content-index-delete

Tương thích trình duyệt

Xem thêm