目前使用本地占位图来显示书籍封面。如果数据库中的 coverUrl 为空或加载失败,会显示一个渐变背景的占位图,上面显示书籍标题。
准备图片:
xiao/images/ 目录修改代码:
在 pages/detail/detail.wxml 中修改:
<image
class="cover"
src="{{content.coverUrl || '/images/books/default-cover.png'}}"
mode="aspectFill"
></image>
在数据库中设置封面URL:
images/books/ 目录下,数据库中的 coverUrl 设置为 /images/books/封面名.png/images/books/huozhe.png上传图片到服务器:
在数据库中设置:
content 表的 cover_url 字段中填入完整的图片URLhttps://your-domain.com/images/covers/huozhe.jpg转换图片为base64:
在代码中使用:
<image
class="cover"
src="{{content.coverUrl || 'data:image/png;base64,iVBORw0KGgoAAAANS...'}}"
mode="aspectFill"
></image>
最佳实践:
/uploads/covers/)cover_url 字段中存储相对路径或完整URL目前使用本地占位图(渐变背景 + 书籍标题文字),如果数据库中的 coverUrl 为空或图片加载失败,会自动显示占位图。占位图使用紫色渐变背景,白色文字显示书籍标题。