当前位置:网站首页>Supplementary usage of upload component in fusiondesign 1
Supplementary usage of upload component in fusiondesign 1
2022-06-23 21:28:00 【Swing a knife North】
Today I'd like to share with you FusionDesign in upload Supplementary usage of components ,Fusion The use methods described in the documentation of are basically dependent on a separate Upload Components to complete , There is another way to use it , The developer of the document did not write it in the document , Today I will show you this method :
import {Upload, Button} from '@alifd/next';
const Selecter = Upload.Selecter;
const Up = ()=>{
const handleSelect = (files) => {
// get files
}
return<Selecter onSelect={this.handleSelect}>
<Button type="primary">Upload File</Button>
</Selecter>
}See the code above , We imported Upload Of selecter This attribute , This attribute is also a component , The inside of this component is like this :
<script>
function selectFile() {
$('#inputfile').click(); // When the parent node is clicked, it is triggered automatically input Click on
}
function onSelect(target) {
console.log(target.files); // Get file object File
}
</script>
<div role="upload" onclick="selectFile()">
<input type="file" style="display: none;" id="inputfile" onchange="onSelect(this)">
<button>Upload File</button>
</div>Listen for the outermost click event , Then the trigger input Click events for , triggering input:file The interface for selecting files , When the user selects a file , Trigger chang event , call onSelect Method , Components will onSlect Method is exposed to the parameters of the build , So you can get the file object .
Look at the second step :
import {Upload, Button} from '@alifd/next';
const Selecter = Upload.Selecter; // File selector
const Uploader = Upload.Uploader; // File uploader
const Up = ()=>{
const uploader = new Uploader({
action: '/api/upload',
//onProgress: this.onProgress // Progress monitoring
});
handleSelect = (files) => {
// Upload files
uploader.startUpload(files);
}
return <Selecter onSelect={this.handleSelect}>
<Button type="primary">Upload File</Button>
</Selecter>
}Compared with the previous code , This segment is imported Uploader One of the Uploader attribute , This attribute value is a class , The instance of this class has the method of uploading files , How to use it , Instantiate an object first , Configuration parameters can be passed during instantiation , Such as action It's the upload address . Get an example , And then call startUpload Upload files .
I don't know if any students have found the problem with the above code , We didn't set the file fields name, There are two ways to set ,uploader When instantiating or calling setOptions Method :
import {Upload, Button} from '@alifd/next';
const Selecter = Upload.Selecter; // File selector
const Uploader = Upload.Uploader; // File uploader
const Up = ()=>{
const uploader = new Uploader({
action: '/api/upload',
// name:'image'
//onProgress: this.onProgress // Progress monitoring
});
handleSelect = (files) => {
// Upload files
uploader.setOptions({name:'image'})
uploader.startUpload(files)
}
return <Selecter onSelect={handleSelect}>
<Button type="primary">Upload1111 File</Button>
</Selecter>
}The above is Fusion Design Of Upload Share other usage methods of components , I hope it helped you .
边栏推荐
- Bypass memory integrity check
- Beitong G3 game console unpacking experience. It turns out that mobile game experts have achieved this
- Wechat is new. You can create applications from Excel
- Spend small money to do big things: cloud function + cloud development leverages the practice of e-commerce promoting flexible architecture in CCTV evening party
- 同花顺股票开户是安全的吗?
- Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create
- Uniapp routing page Jump
- What can RFID fixed assets management system bring to enterprises?
- Full text search of MySQL
- How to gradually improve PMO's own ability and management level
猜你喜欢
![Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text](/img/b1/71cc36c45102bdb9c06e099eb42267.jpg)
Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text

I am 30 years old, no longer young, and have nothing

Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create

New SQL syntax quick manual!

How PMO uses two dimensions for performance appraisal

Steps for formulating the project PMO strategic plan

How to view the role of PMO in agile organizations?

Gradle asked seven times. You should know that~

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

How does PMO select and train project managers?
随机推荐
Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text
Gradle asked seven times. You should know that~
【5分钟玩转Lighthouse】快速使用长安链
Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create
ZABBIX custom monitoring item (server monitoring)
Those programmers wrote super funny 56 code comments (worth collecting)!!
Beitong G3 game console unpacking experience. It turns out that mobile game experts have achieved this
Infrastructure splitting of service splitting
游戏安全丨喊话CALL分析-写代码
Customize view to imitate today's headlines and like animation!
我在深圳,到哪里开户比较好?在线开户安全么?
How to batch generate UPC-A codes
How to build a personal cloud game server? How many games can the cloud game platform install?
上线项目之局域网上线软件使用-----phpStudy
From different angles, you can learn about the implementation of sliding list in fluent
What is the process of opening a mobile card account? Is online account opening safe?
Memory patch amsi bypass
How to expand the capacity of ECS disk? What are the advantages of using cloud disk
Drawing STM32 minimum system schematic diagram with AD
Steps for formulating the project PMO strategic plan