默认图

This commit is contained in:
李志鹏
2026-06-02 14:44:06 +08:00
parent 15dd98a555
commit 2c5ef21edb
3 changed files with 6 additions and 3 deletions

View File

@@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, onUnmounted, reactive, toRefs } from 'vue' import { ref, onMounted, onUnmounted, reactive, toRefs } from 'vue'
import nullImg from '@/assets/images/shopping-cart-null.png'
const props = defineProps({ const props = defineProps({
url: { url: {
type: String, type: String,
@@ -42,7 +41,7 @@
</script> </script>
<template> <template>
<div class="commodity-item" :class="{ 'is-download': download }"> <div class="commodity-item" :class="{ 'is-download': download }">
<img :src="nullImg" v-loadimg="props.url" alt="" @click="openDetail" /> <img v-loadimg="props.url" alt="" @click="openDetail" />
<div class="detail"> <div class="detail">
<div class="text"> <div class="text">
<div class="name"> <div class="name">

View File

@@ -1,6 +1,10 @@
import img from '@/assets/images/shopping-cart-null.png'
// 加载图片 // 加载图片
export default { export default {
name: 'loadimg', name: 'loadimg',
beforeMount(el, binding) {
if (!el.src) el.src = img
},
mounted(el, binding) { mounted(el, binding) {
const src = binding.value const src = binding.value
if (el.src === src) return if (el.src === src) return

View File

@@ -7,7 +7,7 @@
}" }"
> >
<slot name="checkbox" /> <slot name="checkbox" />
<img :src="info.cover" /> <img v-loadimg="info.cover" />
<div class="content"> <div class="content">
<div class="title">{{ info.title }}</div> <div class="title">{{ info.title }}</div>
<div class="brand" v-if="showBrand" @click="handleBrandClick"> <div class="brand" v-if="showBrand" @click="handleBrandClick">