i
This commit is contained in:
62
src/components/Upload.vue
Normal file
62
src/components/Upload.vue
Normal file
@@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<view>
|
||||
<nut-uploader
|
||||
v-model:file-list="fileList"
|
||||
:url="config.url"
|
||||
:maximum="max"
|
||||
:headers="config.headers"
|
||||
@success="success"
|
||||
@failure="failure"
|
||||
:multiple="false"
|
||||
></nut-uploader>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BASE_URL } from "@/utils/request";
|
||||
import { computed, ref } from "vue";
|
||||
import Taro from "@tarojs/taro";
|
||||
|
||||
const props = defineProps({
|
||||
list: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
});
|
||||
|
||||
const emits = defineEmits(["update:list"]);
|
||||
|
||||
const fileList = computed({
|
||||
get: () => props.list,
|
||||
set: (val) => emits("update:list", val),
|
||||
});
|
||||
|
||||
const config = ref({
|
||||
url: `${BASE_URL}/upload`,
|
||||
headers: {
|
||||
token: Taro.getStorageSync("token"),
|
||||
},
|
||||
});
|
||||
|
||||
const success = (res: any) => {
|
||||
const data = JSON.parse(res.responseText.data);
|
||||
res.fileItem.url = data.data.data;
|
||||
Taro.showToast({
|
||||
title: "上传成功",
|
||||
icon: "success",
|
||||
});
|
||||
};
|
||||
|
||||
const failure = () => {
|
||||
Taro.showToast({
|
||||
title: "上传失败",
|
||||
icon: "error",
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss"></style>
|
||||
Reference in New Issue
Block a user