Skip to content

Commit e9d7970

Browse files
committed
增加 vue hooks plus 插件示例
1 parent 5b01a1f commit e9d7970

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"vue": "^3.4.21",
5757
"vue-currency-input": "^3.1.0",
5858
"vue-esign": "^1.1.4",
59+
"vue-hooks-plus": "^1.8.9",
5960
"vue-m-message": "^4.0.2",
6061
"vue-router": "^4.3.0",
6162
"vue3-count-to": "^1.1.2",

pnpm-lock.yaml

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/router/modules/plugin.example.ts

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ const routes: RouteRecordRaw = {
1414
icon: 'i-clarity:plugin-outline-alerted',
1515
},
1616
children: [
17+
{
18+
path: 'hooksplus',
19+
name: 'pluginExampleHooksPlus',
20+
component: () => import('@/views/plugin_example/hooks.plus.vue'),
21+
meta: {
22+
title: 'VueHooks Plus',
23+
icon: 'https://inhiblabcore.github.io/docs/hooks/logo.svg',
24+
},
25+
},
1726
{
1827
path: 'qrcode',
1928
name: 'pluginExampleQrcode',
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<route lang="yaml">
2+
meta:
3+
enabled: false
4+
</route>
5+
6+
<script lang="ts" setup>
7+
import { useRequest } from 'vue-hooks-plus'
8+
import Alert from './components/alert.vue'
9+
10+
function getUsername(): Promise<string> {
11+
return new Promise((resolve) => {
12+
setTimeout(() => {
13+
resolve(String(Date.now()))
14+
}, 1000)
15+
})
16+
}
17+
18+
const time = ref(900)
19+
20+
const computedTime = computed(() => time.value + 100)
21+
22+
const { data, run, loading, cancel } = useRequest(() => getUsername(), {
23+
manual: true,
24+
pollingInterval: computedTime,
25+
pollingWhenHidden: false,
26+
})
27+
28+
function start() {
29+
run()
30+
}
31+
32+
function update() {
33+
time.value += 100
34+
}
35+
36+
function open(url: string) {
37+
window.open(url, '_blank')
38+
}
39+
</script>
40+
41+
<template>
42+
<div>
43+
<Alert />
44+
<PageHeader title="VueHooks Plus">
45+
<template #content>
46+
<p>提供基础和高级的 hook ,高性能逻辑的抽象封装,满足大量场景,更多 API 和例子请查看 VueHooks Plus 官网。</p>
47+
<p style="margin-bottom: 0;">
48+
安装命令:<ElTag>pnpm add vue-hooks-plus</ElTag>
49+
</p>
50+
</template>
51+
<ElButton @click="open('https://github.com/InhiblabCore/vue-hooks-plus')">
52+
<template #icon>
53+
<SvgIcon name="i-ep:link" />
54+
</template>
55+
访问 VueHooks Plus
56+
</ElButton>
57+
</PageHeader>
58+
<PageMain title="轮询">
59+
<div class="mb-4">
60+
Data:<span>{{ loading ? 'loading' : data }}</span>
61+
</div>
62+
<div class="mb-4">
63+
PollingInterval:{{ computedTime }}ms
64+
</div>
65+
<div>
66+
<el-button @click="start()">
67+
Start
68+
</el-button>
69+
<el-button @click="update()">
70+
time + 100ms
71+
</el-button>
72+
<el-button @click="cancel()">
73+
Stop
74+
</el-button>
75+
</div>
76+
</PageMain>
77+
</div>
78+
</template>

0 commit comments

Comments
 (0)