当前位置:网站首页>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 .
边栏推荐
- There is a 1GB difference between truncatememory and removememory
- Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create
- Customize view to imitate today's headlines and like animation!
- 我在深圳,到哪里开户比较好?在线开户安全么?
- What are the server host security risks? How to prevent safety risks?
- The new track of flagship chip is finally clear
- Share a super Mary source code
- Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
- Process crash does not generate dump. Configure localdumps
- [etcd] etcd usage and cluster construction
猜你喜欢

Four aspects of PMO Department value assessment

How to view the role of PMO in agile organizations?

How PMO uses two dimensions for performance appraisal

How does PMO select and train project managers?

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

How to gradually improve PMO's own ability and management level

New SQL syntax quick manual!

Beitong G3 game console unpacking experience. It turns out that mobile game experts have achieved this

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse

Steps for formulating the project PMO strategic plan
随机推荐
Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
How to solve the problem that the ID is not displayed when easycvr edits the national standard channel?
Development and code analysis of easycvr national standard user defined streaming address function
Use Tencent cloud lightweight application server to build an unlimited network disk -zpan building tutorial
How to gradually improve PMO's own ability and management level
[Debian] Debian usage notes
Overview of digital circuits
网上证券开户安全还是去营业部安全
How to handle the prompt that DNS is incorrect when adding resolution to Tencent cloud?
Easyplayer player error 502 bad gateway problem analysis
How to use smart cloud disk service differences between local disk service and cloud disk service
SAP retail uses transaction code wb03 to display a factory configured in the background
How to batch generate UPC-A codes
How to Net project migration to NET Core
How to build a cloud game platform on the server? How to select a cloud game server?
Nodejs operation state keeping technology cookies and sessions
Wechat smart operation 3.0+ Alipay digital transformation 3.0
Using asp Net core MVC framework for building web applications
Gradle asked seven times. You should know that~
Copilot - employee, your layoff notice has been delivered