当前位置:网站首页>File upload JS
File upload JS
2022-06-13 08:42:00 【huangxunlove】
design sketch
html Code :
<template>
//intl Is an introduced function , The main function is to convert the title from Chinese to English ,formData It's a json The
<div title>{
{ intl(formData['resume']) }}</div>
<div>
// Pay attention to this input type , To open the local folder after clicking ;accept Yes, the selected file type can only be pdf;
<input type="file" accept="application/pdf" ref="fileInput" style="display:none">
// there v-if Is to determine whether there is a selected file , If selected, the file name... Is displayed
<div class="file_message" v-if="resumeName !== ''">
// Show front here pdf Icon
<div class="img"><i class="fas fa-file-pdf"></i></div>
<div class="content">
<span class="file_name">{
{resumeName}}</span>
<div class="file_size">{
{fileSize}}</div>
<span class="operation" style=" display:flex; position: absolute; right: 0.5em; bottom: 0.5em; font-size: 0.6em;">
//Button It refers to another component
<Button :type="['', 'blue'].join(' ')" :name=" intl({ 'en-US': 'Reselect', 'zh-CN': ' To choose ', }) " @click="uploadFile" />
<Button :type="['', 'red'].join(' ')" :name=" intl({ 'en-US': 'Delete', 'zh-CN': ' Delete ', }) " @click="deleteFile" />
</span>
</div>
</div>
// And the above v-if Corresponding
<div class="upload" v-else @click="uploadFile">
<i></i>
<span>
{
{
intl({
"en-US": "Select file (maximum 10M)",
"zh-CN": " Select File ( Maximum limit 10M)",
})
}}
</span>
</div>
</div>
</template>
css Code :
<style scoped> .upload {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 7em;
padding: 0;
border-radius: 5px;
background-color: var(--gray-background);
color: var(--gray-bright);
}
.upload i {
width: 2.5em;
height: 2.5em;
margin: 0.5em auto 0.3em;
background: url(https://s1.wenjuan.com/static/img/q_upload_file/upload-pc.svg) no-repeat;
}
.upload span {
font-size: 0.8em;
color: var(--gray);
opacity: 0.5;
}
.file_message {
box-sizing: border-box;
display: flex;
align-items: center;
position: relative;
background-color: var(--gray-background);
padding: 1em;
border: 1px solid var(--gray-border);
border-radius: 5px;
}
.file_message .img {
font-size: 2.8em;
color: var(--gray);
padding-right: 0.5em;
}
.file_name {
font-size: 1.2em;
color: var(--gray);
}
.file_size {
margin-top: 0.5em;
font-size: 0.8em;
color: var(--gray);
opacity: 0.6;
}
</style>
js Code :
<script>
import {
intl } from '/util/env.js'
import {
formData } from '/apply/formData.json'
export default {
// Pass up update function
emits: ['update'],
data() {
return {
formData,
resumeName: '',
fileSize: '',
fileType: '',
}
},
methods: {
uploadFile() {
let fileInput = this.$refs.fileInput
fileInput.click()
fileInput.onchange = () => {
let file = fileInput.files[0]
let resumeSize = file.size
if (resumeSize / (1024 * 1024) > 10) {
alert(' Limit 10MB within ')
return false
} else {
if (resumeSize >= 1024 && resumeSize < 1048576) {
this.fileSize = parseFloat((resumeSize / 1024).toFixed(2)) + 'KB'
} else if (resumeSize >= 1048576) {
this.fileSize = parseFloat((resumeSize / 1048576).toFixed(2)) + 'M'
} else {
this.fileSize = parseFloat(resumeSize.toFixed(2)) + 'B'
}
}
this.resumeName = file.name
console.log(file)
}
},
update(fileInput = false) {
if (!fileInput) {
this.$refs.fileInput.blur()
} else {
this.$emit('update', this.$refs.fileInput.files[0])
}
},
deleteFile() {
this.resumeName = ''
},
intl,
},
}
</script>
边栏推荐
- Dest0g3 520 orientation
- redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
- Dest0g3 520 orientation
- SQL injection experiment
- Svg text stroke effect
- DNS domain name resolution service
- 0. some doubts about learning SolidWorks for the first time
- MySQL queries difference sets (missing data) by linking tables based on an associated field
- Vscode define code block -- define cursor position
- CCNP_ Summary (Continued)
猜你喜欢
Yarn package management tool
Differences and uses among cookies, localstorage, sessionstorage, and application caching
Penetration problem (main directory, password explosion, database uploading Trojan horse)
JS array using the reduce() method
HCIP_ MGRE comprehensive experiment
Shellshock Attack Lab
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
Using KVM to create three virtual machines that can communicate with local area network
SQL injection question type (manual injection +sqlmap)
Buuctf web (VII)
随机推荐
About RSA encryption and decryption principle
MySQL parsing serialized fields
Emotion handling skills
Microservice system architecture construction I: Environment Construction
Buuctf web (V)
Custom exception class myexception
ADT Google browser plug-in ad Terminator
PHP PNG to webp
Namespace in TS (2)
顺时针打印个数组
Logstash failed to create queue
Dest0g3 520迎新赛
DIY无人机(匿名拓控者P2+F330机架)
\Difference between N and \r
File upload question type
JS array method
JS - simple ATM of the for cycle case
Homestead environment setup
Buuctf web (III)
Browser render passes