【问题标题】:Removing the http protocol from an image URL?从图像 URL 中删除 http 协议?
【发布时间】:2023-03-20 20:02:01
【问题描述】:

我正在查看从图像 URL 中删除 http 的代码,想知道他们为什么要这样做?:


  get thumbnail(): string | boolean {
    if (this.book.volumeInfo.imageLinks) {
      return this.book.volumeInfo.imageLinks.smallThumbnail.replace(
        'http:',
        ''
      );
    }

对应的角模板如下:

<img mat-card-sm-image *ngIf="thumbnail" [src]="thumbnail"/>

这是完整的堆栈闪电战:

https://stackblitz.com/edit/akita-books-store-refactor-fullscreen?file=example-app%2Fapp%2Fbooks%2Fcomponents%2Fbook-preview.component.ts

如果有人好奇,图片 url 包含在像这样的谷歌图书 API JSON 文档中:

https://www.googleapis.com/books/v1/volumes/tI5UswEACAAJ

【问题讨论】:

标签: javascript html angular typescript http


【解决方案1】:

它正在从中删除 http,因此 url 成为协议相对 URL。因此,如果页面位于 https:// 下,它将从 https 而不是 http 加载。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-08
    • 2014-11-22
    • 2018-03-04
    • 2018-06-02
    • 2015-12-22
    • 1970-01-01
    • 2011-02-06
    • 2019-05-29
    相关资源
    最近更新 更多