采用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

15
main.js
View File

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

View File

@ -9,7 +9,7 @@
</view>
<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>
</button>
</view>
@ -84,8 +84,6 @@ import { getServiceTerms, getPrivacyPolicy } from '@/api/article/article.js'
import { commonEnum } from '../../enum/commonEnum'
import { getNavBarHeight, getTitleBarHeight } from '../../utils/system'
import throttle from 'uview-ui/libs/function/throttle'
export default {
data() {
return {
@ -254,6 +252,10 @@ export default {
},
goToLogin() {
this.$uv.throttle(this.Login, 3000)
},
Login() {
console.log('开始登录流程')
//

View File

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