one. uni-app implements file upload function
Currently, I have found a third-party plug-
in. The file upload plug-in address is https://ext.dcloud.net.cn/plugin?id=1015
. Download the plug-in and import it into the project for direct use. The plug-in market also has a description of the usage of the plug-in. .
Usage:
1. The following code is written at the top of the first view in the root directory or behind the custom navigation bar
// 以下代码写于根目录下第一个view顶部或跟在自定义导航栏后面
<l-file
ref="lFile"
@up-success="upSuccess"
></l-file>
2.Introduce the imported plug-in into the page you use
import lFile from ‘@/uni_modules/l-file/components/l-file/l-file.vue’
Registering:
components: {
lFile
},
3. File upload
/*
=======选择文件+上传=======
url=上传服务器地址,必填
name=上传文件的key(选填,默认为file)
header=请求头(选填)
*/
this.$refs.lFile.upload({
//替换为你的上传接口地址