// pages/index/index.uvue ,<script setup>标签下这么写
import useCommonTool from '@/hooks/useCommonTool.uts'
const {goto} = useCommonTool()
// pages/index/index.uvue ,<template>标签下这么写
<button @click="goto('/pages/map/index')">查看地图示例</button>
// 相关的 /hooks/useCommonTool.uts 文件里这么写
export default function useCommonTool() {
const goto = (url:string) => {
uni.navigateTo({url:url})
}
return {
// methods
goto,
}
}
- 发布:2025-02-04 10:33
- 更新:2025-02-04 10:33
- 阅读:13
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 4.45
手机系统: Android
手机系统版本号: Android 14
手机厂商: Meizu
手机机型: note21
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
HbuilderX中,运行 -》运行到手机或模拟器 -》运行到Android App底座
HbuilderX中,运行 -》运行到手机或模拟器 -》运行到Android App底座
预期结果:
正常编译,并在手机上正常运行起来。
正常编译,并在手机上正常运行起来。
实际结果:
编译时,服务运行日志报错:
10:29:21.525 [plugin:uni:app-uts] 编译失败
10:29:21.525 error: Unresolved reference: goto
10:29:21.525 at pages/index/index.uvue:20:7
10:29:21.525 18 |
10:29:21.525 19 | // methods
10:29:21.525 20 | const {goto} = useCommonTool()
10:29:21.525 | ^
10:29:21.525 21 | // const goto = (url:string) => {
10:29:21.525 22 | // uni.navigateTo({url:url})
10:29:21.526 error: Not enough information to infer type variable T
10:29:21.526 at pages/index/index.uvue:8:111
10:29:21.526 6 | </view>
10:29:21.526 7 | <view>
10:29:21.526 8 | <button :disabled="true" class="uni-button-primary uni-radius-pill" @click="goto('/pages/map/index')">查看地图示例</button>
10:29:21.526 | ^
10:29:21.526 9 | </view>
10:29:21.526 10 | </view>
编译时,服务运行日志报错:
10:29:21.525 [plugin:uni:app-uts] 编译失败
10:29:21.525 error: Unresolved reference: goto
10:29:21.525 at pages/index/index.uvue:20:7
10:29:21.525 18 |
10:29:21.525 19 | // methods
10:29:21.525 20 | const {goto} = useCommonTool()
10:29:21.525 | ^
10:29:21.525 21 | // const goto = (url:string) => {
10:29:21.525 22 | // uni.navigateTo({url:url})
10:29:21.526 error: Not enough information to infer type variable T
10:29:21.526 at pages/index/index.uvue:8:111
10:29:21.526 6 | </view>
10:29:21.526 7 | <view>
10:29:21.526 8 | <button :disabled="true" class="uni-button-primary uni-radius-pill" @click="goto('/pages/map/index')">查看地图示例</button>
10:29:21.526 | ^
10:29:21.526 9 | </view>
10:29:21.526 10 | </view>
bug描述:
如题,这样的hooks用法在web上正常,但在安卓底座上运行时无效。
uni-app x中uvue对vue3中的hooks特性支持有BUG。
0 个回复