Commit 4d843582 authored by liyang li's avatar liyang li
Browse files

improve upload button

parent 50788473
<script setup> <script setup>
import {NButton} from 'naive-ui' import {NButton,NMessageProvider} from 'naive-ui'
import {NUpload} from 'naive-ui' import UploadButton from './UploadButton.vue'
</script> </script>
<template> <template>
<div class="main-wrapper"> <div class="main-wrapper">
...@@ -8,19 +8,9 @@ ...@@ -8,19 +8,9 @@
<n-button strong secondary type="tertiary"> <n-button strong secondary type="tertiary">
&nbsp;Edit text&nbsp; &nbsp;Edit text&nbsp;
</n-button> </n-button>
<n-upload <n-message-provider>
action="请求提交的地址" <UploadButton/>
:headers="{//HTTP 请求需要附加的 Headers </n-message-provider>
'naive-info': 'hello!'//提交表单需要附加的数据
}"
:data="{
'naive-data': 'cool! naive!'
}"
>
<n-button strong secondary type="tertiary">
Upload File
</n-button>
</n-upload>
</div> </div>
<div class="text-area"> <div class="text-area">
<textarea id="paste-panel" placeholder="Put your paste here" name="input" cols="100" rows="10"></textarea> <textarea id="paste-panel" placeholder="Put your paste here" name="input" cols="100" rows="10"></textarea>
......
<script>
import { defineComponent } from "vue";
import { useMessage,NButton,NUpload } from "naive-ui";
export default defineComponent({
components:{
NButton,
NUpload
},
setup() {
let support=[ 'pdf',
'txt',
'c','cpp','cxx','txx','c++','C','cc','h','hpp','hxx',
'cs',
'java','class',
'py','py3',
'js',
'go',
]
const message = useMessage();
return {
async beforeUpload(data) {
let filename = data.file.file.name.split('.').pop().toLowerCase();
let correctFile = false;
support.forEach(element => {
if(element==filename){
correctFile=true
}
});
if (!correctFile) {
message.error("只能上传pdf,txt,C,C++,C#,Java,Python,JS,Goland文件,请重新上传");
return false;
}
return true;
}
};
}
});
</script>
<template>
<n-upload
multiple
:max="1"
action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f"
@before-upload="beforeUpload"
>
<n-button strong secondary type="tertiary">upload file</n-button>
</n-upload>
</template>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment