Commit db3092db2eb7d5346778847757adb2b9c4041ed5
1 parent
1d45617e
feat: add file download demo
Showing
6 changed files
with
54 additions
and
0 deletions
CHANGELOG.zh_CN.md
src/components/registerGlobComp.ts
... | ... | @@ -6,6 +6,7 @@ import { |
6 | 6 | |
7 | 7 | // Optional |
8 | 8 | Select, |
9 | + Alert, | |
9 | 10 | Checkbox, |
10 | 11 | DatePicker, |
11 | 12 | Radio, |
... | ... | @@ -48,6 +49,7 @@ export function registerGlobComp() { |
48 | 49 | // If you don’t need it, you can delete it |
49 | 50 | getApp() |
50 | 51 | .use(Select) |
52 | + .use(Alert) | |
51 | 53 | .use(Checkbox) |
52 | 54 | .use(DatePicker) |
53 | 55 | .use(Radio) | ... | ... |
src/router/menus/modules/demo/feat.ts
... | ... | @@ -4,6 +4,9 @@ const menu: MenuModule = { |
4 | 4 | menu: { |
5 | 5 | name: '功能', |
6 | 6 | path: '/feat', |
7 | + tag: { | |
8 | + dot: true, | |
9 | + }, | |
7 | 10 | children: [ |
8 | 11 | { |
9 | 12 | path: 'icon', |
... | ... | @@ -18,6 +21,13 @@ const menu: MenuModule = { |
18 | 21 | name: '右键菜单', |
19 | 22 | }, |
20 | 23 | { |
24 | + path: 'download', | |
25 | + name: '文件下载', | |
26 | + tag: { | |
27 | + content: 'new', | |
28 | + }, | |
29 | + }, | |
30 | + { | |
21 | 31 | path: 'click-out-side', |
22 | 32 | name: 'ClickOutSide', |
23 | 33 | }, | ... | ... |
src/router/routes/modules/demo/feat.ts
... | ... | @@ -41,6 +41,14 @@ const feat: AppRouteModule = { |
41 | 41 | }, |
42 | 42 | }, |
43 | 43 | { |
44 | + path: '/download', | |
45 | + name: 'DownLoadDemo', | |
46 | + component: () => import('/@/views/demo/feat/download/index.vue'), | |
47 | + meta: { | |
48 | + title: '文件下载', | |
49 | + }, | |
50 | + }, | |
51 | + { | |
44 | 52 | path: '/click-out-side', |
45 | 53 | name: 'ClickOutSideDemo', |
46 | 54 | component: () => import('/@/views/demo/feat/click-out-side/index.vue'), | ... | ... |
src/utils/file/FileDownload.ts
src/views/demo/feat/download/index.vue
0 → 100644
1 | +<template> | |
2 | + <div class="m-5 demo-box"> | |
3 | + <a-alert message="根据后台接口文件流下载" /> | |
4 | + <a-button type="primary" class="my-4" @click="handleDownByData"> 文件流下载 </a-button> | |
5 | + | |
6 | + <a-alert message="根据文件地址下载文件" /> | |
7 | + | |
8 | + <a-button type="primary" class="my-4" @click="handleDownloadByUrl"> 文件地址下载 </a-button> | |
9 | + </div> | |
10 | +</template> | |
11 | +<script lang="ts"> | |
12 | + import { defineComponent } from 'vue'; | |
13 | + import { downloadByUrl, downloadByData } from '/@/utils/file/FileDownload'; | |
14 | + | |
15 | + export default defineComponent({ | |
16 | + setup() { | |
17 | + function handleDownByData() { | |
18 | + downloadByData('text content', 'testName.txt'); | |
19 | + } | |
20 | + function handleDownloadByUrl() { | |
21 | + downloadByUrl({ | |
22 | + url: 'https://codeload.github.com/anncwb/vue-vben-admin-doc/zip/master', | |
23 | + target: '_self', | |
24 | + }); | |
25 | + } | |
26 | + return { | |
27 | + handleDownloadByUrl, | |
28 | + handleDownByData, | |
29 | + }; | |
30 | + }, | |
31 | + }); | |
32 | +</script> | ... | ... |