<div
class="product-container"
:style="{ backgroundImage: 'url(' + productBG + ')' }"
>
<!-- 商品内容 -->
</div>
data() {
return {
productBG: '', // 初始化背景图片 URL
};
},
async getBackground() {
try {
// 假设接口返回的数据结构为 { imageUrl: 'https://example.com/image.jpg' }
const response = await fetch('https://api.example.com/product');
const data = await response.json();
this.productBG = data.imageUrl; // 将接口返回的图片 URL 赋值给 productBG
} catch (error) {
console.error('获取背景图片失败:', error);
}
},

被折叠的 条评论
为什么被折叠?



