采用this.$uv.xxx方式使用api实现节流

This commit is contained in:
WindowBird 2025-09-04 13:47:52 +08:00
parent 30279799b5
commit 1d565c9531
3 changed files with 22 additions and 5 deletions

11
main.js
View File

@ -3,7 +3,13 @@ import App from './App'
// #ifndef VUE3 // #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
import './uni.promisify.adaptor' import './uni.promisify.adaptor'
import uvUI from '@/uni_modules/uv-ui-tools'
Vue.config.productionTip = false Vue.config.productionTip = false
// 全局安装 uvUI
Vue.use(uvUI)
App.mpType = 'app' App.mpType = 'app'
const app = new Vue({ const app = new Vue({
...App, ...App,
@ -15,6 +21,7 @@ app.$mount()
import { createSSRApp } from 'vue' import { createSSRApp } from 'vue'
import PageScrollMixin from './mixins/page-scroll-mixin.js' import PageScrollMixin from './mixins/page-scroll-mixin.js'
import store from './store/index.js' import store from './store/index.js'
import uvUI from '@/uni_modules/uv-ui-tools'
export function createApp() { export function createApp() {
const app = createSSRApp(App) const app = createSSRApp(App)
@ -25,8 +32,12 @@ export function createApp() {
// 注册 store // 注册 store
app.use(store) app.use(store)
// Vue3 方式注册 uvUI
app.use(uvUI)
return { return {
app, app,
} }
} }
// #endif // #endif

View File

@ -9,7 +9,7 @@
</view> </view>
<view class="main-content"> <view class="main-content">
<!-- 登录按钮 --> <!-- 登录按钮 -->
<button :disabled="loginLoading" class="login-btn" @click="throttle()(goToLogin, 3000)"> <button :disabled="loginLoading" class="login-btn" @click="goToLogin">
<text class="btn-text">{{ loginLoading ? '登录中...' : '微信用户一键登录' }}</text> <text class="btn-text">{{ loginLoading ? '登录中...' : '微信用户一键登录' }}</text>
</button> </button>
</view> </view>
@ -84,8 +84,6 @@ import { getServiceTerms, getPrivacyPolicy } from '@/api/article/article.js'
import { commonEnum } from '../../enum/commonEnum' import { commonEnum } from '../../enum/commonEnum'
import { getNavBarHeight, getTitleBarHeight } from '../../utils/system' import { getNavBarHeight, getTitleBarHeight } from '../../utils/system'
import throttle from 'uview-ui/libs/function/throttle'
export default { export default {
data() { data() {
return { return {
@ -254,6 +252,10 @@ export default {
}, },
goToLogin() { goToLogin() {
this.$uv.throttle(this.Login, 3000)
},
Login() {
console.log('开始登录流程') console.log('开始登录流程')
// //

View File

@ -12,6 +12,10 @@
<script> <script>
export default { export default {
mounted() {
console.log('uvUI 可用性:', !!this.$uv)
console.log('debounce 方法:', !!this.$uv?.debounce)
},
data() { data() {
return { return {
currentLocation: {}, currentLocation: {},