liudong
2024-08-20 a0d37a5078faea38bd7c46953f228cfb99a600c2
src/components/upload/index.vue
@@ -5,12 +5,16 @@
    :limit="limit"
    :action="action"
    @change="handleChange"
    @before-remove="beforeRemove"
    image-preview
  />
</template>
<script setup>
  import { computed, ref, watch, watchEffect } from 'vue';
  import { computed, ref, onMounted, watch, watchEffect } from 'vue';
  import { useUserStore } from '@/store';
  const userStore = useUserStore();
  const props = defineProps({
    limit: {
      type: Number,
@@ -20,8 +24,8 @@
    url: String, //回显的文件地址
  });
  const emit = defineEmits(['update:fileList', 'success']);
  const emit = defineEmits(['update:fileList', 'success', 'handleRemove']);
  const urls = computed(() => props.url);
  const fileList = ref([]);
  watch(
@@ -41,7 +45,28 @@
    }
  );
  onMounted(() => {
    if (urls.value) {
      fileList.value = urls.value.split(',').map((item) => ({
        uid: item,
        name: item,
        status: 'done',
        url: item,
      }));
    }
    // console.log(
    //   window.location.origin,
    //   import.meta.env.VITE_API_BASE_URL,
    //   8988
    // );
  });
  // console.log(urls.value, 8988);
  const beforeRemove = (file) => {
    emit('handleRemove');
    fileList.value = [];
  };
  const handleChange = (fileList) => {
    emit('update:fileList', fileList);