uniapp插件uViewplus的使用(涉及TS下的问题)

在技术选型后最后定了使用有团队维护的uview-plus3.0,官方文档

配置参考:https://juejin.cn/post/7169875753100640270

ts配置参考:https://blog.csdn.net/m0_70027114/article/details/132957426

引入

在项目文件的pages.json中的"easycom"."custom": 添加如下

复制代码
"easycom": {
	"autoscan": true,
	"custom": {
		......
		"^u--(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue",
		"^up-(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue",
		"^u-([^-].*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue"
	}
},

main.js文件中引入插件

复制代码
// 引入全局uview-plus
 import uviewPlus from './uni_modules/uview-plus/index.js'

 const app = createSSRApp(App)
 app.use(uviewPlus)
 
 return {
  app
 }

TS相关

创建env.d.ts

复制代码
declare module '@/uni_modules/uview-plus';

并写入tsconfig.json

复制代码
{	
	"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
	"typeRoots": [
		"@/env.d.ts"
	]
}

遇到的问题

我的vue3项目使用了ts,这个插件引入之后就开始报uni. u 属性不存在,但不影响运行。因为 u属性不存在,但不影响运行。 因为 u属性不存在,但不影响运行。因为u认不出来,他和下面的属性没有提示,书写起来不方便,容易写错。

参考了两个官方论坛的解决方案

https://ask.dcloud.net.cn/question/163482

https://ask.dcloud.net.cn/question/141695

编译器HBuilder3.99 是允许的

https://www.cnblogs.com/00544--/p/17097648.html

复制代码
declare module 'uview-plus' {  
  export function install(): void  //必要
  interface test {  
    /** 邮箱格式校验 */  
    email(email: string): boolean  
  }  
  interface $u {  
    test: test  
  }  

  global {  
    interface Uni {  
      $u: $u  
    }  
  }  
}

猜测需要将所有用到的类型一一注册,才能作为属性调用,uView的属性还挺多的,工程量有点大就没写

相关推荐
沙蒿同学13 小时前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github
变与不变80614 小时前
jQuery细节以及使用应用场景
前端·javascript·jquery
SailingCoder15 小时前
【封闭结束1】端到端交付:Agent 一次请求如何走完全链路
前端·安全·ai·面试·agent·harness
风骏时光牛马17 小时前
AI多模块协同自动化工作流
前端
zhangminghuan17 小时前
前端面试应对技巧
前端·面试·职场和发展
计算机魔术师18 小时前
潜伏14年的PHP致命洞,AI跑两天就交卷了
前端
IT_陈寒18 小时前
Vue的这个响应式陷阱我居然现在才发现
前端·人工智能·后端
Python自动化直播19 小时前
智能脚本批量管理拆开看:导入、导出、重写、试听
前端·python·ai·秒播
开开心心就好19 小时前
发票信息录入太麻烦?离线工具一键转表格
运维·服务器·前端·pdf·ocr·maven·intellij-idea