docs: ✏️ utils

This commit is contained in:
chenxiaohui
2024-08-05 11:22:13 +08:00
parent e455b9790b
commit 0ac07cb82d
4 changed files with 75 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 KiB

View File

@@ -0,0 +1,59 @@
<template>
<div>
<XAction
label="downloadUrl"
type="primary"
@click="onDownloadUrl"></XAction>
<XAction
label="downloadBlob"
type="primary"
@click="onDownloadBlob"></XAction>
<XAction
label="downloadRemoteFile"
type="primary"
@click="onDownloadRemoteFile"></XAction>
<XAction
label="downloadJson"
type="primary"
@click="onDownloadJson"></XAction>
</div>
</template>
<script setup lang="ts">
import { XAction } from '@vtj/ui';
import {
downloadUrl,
downloadBlob,
downloadRemoteFile,
downloadJson
} from '@vtj/utils';
import { fileToBase64 } from '@vtj/utils';
const onDownloadUrl = () => {
downloadUrl(
'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg',
'elementUI.jpeg'
);
};
const onDownloadBlob = async () => {
const blobParts = ['<q id="a"><span id="b">hey!</span></q>']; // 一个包含单个字符串的数组
const blob = new Blob(blobParts, { type: 'text/html' }); // 得到 blob
downloadBlob(blob);
};
const onDownloadRemoteFile = async () => {
downloadRemoteFile('./background.jpg', 'background.jpg', 'image/jpg');
};
const onDownloadJson = () => {
downloadJson('{name:"aa",age:"22"}', 'a.json');
};
</script>
<style scoped></style>