Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
liyang li
Pastebin00
Commits
4d843582
Commit
4d843582
authored
Oct 09, 2022
by
liyang li
Browse files
improve upload button
parent
50788473
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/components/Main.vue
View file @
4d843582
<
script
setup
>
<
script
setup
>
import
{
NButton
}
from
'
naive-ui
'
import
{
NButton
,
NMessageProvider
}
from
'
naive-ui
'
import
{
N
Upload
}
from
'
naive-ui
'
import
Upload
Button
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"
>
Edit text
Edit text
</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>
...
...
src/components/UploadButton.vue
0 → 100644
View file @
4d843582
<
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
>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment