fileRead.uvue 1.8 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<template>
	<view>
		<page-head :title="title"></page-head>
		<view class="uni-btn-v uni-common-mt">
			<button type="primary"  @tap="getImageBase64">读取图片base64</button>
			<button type="primary"  @tap="getFileText">读取文本内容</button>
		</view>
	</view>
</template>
<script>
	
	import { readFile,writeFile, ReadFileOptions, WriteFileOptions } from '../../uni_modules/uts-file-manager'
	
	
	export default {
		
		data() {
			return {
				title: '文件读取示例',
				logo:""
			}
		},

		methods: {
			
			getImageBase64:function(){
				readFile({
					type:'base64',
					path:'static/logo.png',
					success:function(res){
						console.log("success")
						console.log(res)
					},
					fail:function(res){
						console.log('fail')
						console.log(res)
					},
					complete:function(res){
						console.log("complete")
						console.log(res)
					}
				} as ReadFileOptions)
			},
			getFileText:function(){
				writeFile({
					path:'/test/1.txt',
					content:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦',
					success:function(res){
						readFile({
							type:'text',
							path:res.filePath,
							success:function(res){
								console.log("success")
								console.log(res)
							},
							fail:function(res){
								console.log('fail')
                                console.log(res)
							},
							complete:function(res){
								console.log("complete")
                                console.log(res)
							}
						} as ReadFileOptions)
					},
					fail:function(res){
						console.log('fail')
                        console.log(res)
					},
					complete:function(res){
						console.log("complete")
                        console.log(res)
					}
				} as WriteFileOptions)
			}
		}
	}
</script>

<style>

  
</style>