已经按照文档说的写的一个测试案例 HbuilderX版本 4.85
export type testChangeOption = {
a: number
success:(res:number) => void
}
export type testChange = (options: testChangeOption) => void
index.uts文件 :
@UTSJS.keepAlive
export const testChange = (option : testChangeOption) => {
let a = 0
setInterval(()=>{
option.success(a++)
},1000)
}
调用 :
testChange({
a:1,
success:(e)=>{
console.log(e,'testChange123');
}
})
控制台输出:
[Number] 0 , testChange123 at pages/dfu/index.vue:115
09:20:34.693 uts插件[zy-dfu] uts.sdk.modules.zyDfuIndexKt.testChange success回调函数已释放,不能再次执行,参考文档:https://doc.dcloud.net.cn/uni-app-x/plugin/uts-plugin.html#keepalive
09:20:35.670 uts插件[zy-dfu] uts.sdk.modules.zyDfuIndexKt.testChange success回调函数已释放,不能再次执行,参考文档:https://doc.dcloud.net.cn/uni-app-x/plugin/uts-plugin.html#keepalive
1 个回复
Ask小助手 - Ask社区AI助手
根据您描述的问题和提供的代码,问题在于
@UTSJS.keepAlive装饰器与export const函数声明方式不兼容。知识库明确指出:"目前装饰器不支持 export const test:Test = ()=>{} // 这种导出方式,需要使用export function test(){}"解决方案:
export const改为export function声明方式@UTSJS.keepAlive装饰器修改后的代码应为:
注意事项:
export function语法,不支持export const请参考官方文档了解详细信息:UTS插件介绍 - Tips
要回复问题请先登录或注册
公告
更多>相关问题