uni-app导入文档文件

本文档详细介绍了如何在uni-app中导入并使用文档文件。首先,你需要从指定地址下载插件,然后选择合适版本进行导入。接着,在项目中正确引入插件,将<file-l ref="lFile" @up-success="onSuccess">放置在页面最前面,以便实现文档上传成功后的处理方法。

准备

下载插件

插件地址 https://ext.dcloud.net.cn/plugin?id=1015
选择版本导入插件
在这里插入图片描述

引入

import lFile from '@/components/l-file/l-file.vue'


components: {
			lFile
		},

使用

<l-file ref=“lFile” @up-success=“onSuccess”>放在最前面

<template>
	<view class="fz">
		<l-file ref="lFile" @up-success="onSuccess"></l-file>
		<view class="item">
			<view class="tit"><text class="write">*</text>文档名称
			</view>
			<view class="content">
				<input placeholder="请输入文档名称" placeholder-class="placeholderclass" v-model="form.fileName" class="val" />
				<span class="iconfont icon-shanchu del" v-show="form.fileName.length>0"
					@click="delm('fileName')"></span>
			</view>
		</view>

		<view class="item">
			<view class="tit"><text class="write">*</text>档案文件</view>
			<button type="primary" size="mini" @tap="onUpload">上传文件</button>

		</view>
		

		<!-- <button class="submit blueBtn" hover-class="btnBlueHoverclass" @click="submit">确定</button> -->

	</view>
</template>

方法

/* 上传 */
			onUpload() {
				var token = uni.getStorageSync('token')
				this.$refs.lFile.upload({
					// #ifdef APP-PLUS
					currentWebview: this.$mp.page.$getAppWebview(),
					// #endif
					url: 'http://8.135.112.236/prod-api/gk/file/uploadArchivesFile?archivesDataId=' + this.archivesDataId +
					 "&archivesId=" + this.archivesId + "&archivesStatus="
					 + this.form.archivesStatus + "&fileName=" + this.form.fileName 
					 + "&isShare=" +this.form.isShare,
					 name: 'file',
					header: {'Authorization':'Bearer ' + token},
				});
			},
			onSuccess(res) {
				//console.log('上传成功回调=====33====', JSON.stringify(res.data),res.data.statusCode)
				if(res.data.statusCode==200){
					uni.showToast({
						title: '上传成功!',
					})
					this.form={
					fileName: '',
					archivesStatus: 1,
					isShare: 1,
					}
				}else{
					uni.showToast({
						title: '上传失败!',
						icon:'none'
					})
				}
				
			},
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值