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的属性还挺多的,工程量有点大就没写

相关推荐
Halo_tjn1 小时前
基于封装的专项 知识点
java·前端·python·算法
有来技术2 小时前
Spring Boot 4 + Vue3 企业级多租户 SaaS:从共享 Schema 架构到商业化套餐设计
java·vue.js·spring boot·后端
东东5163 小时前
学院个人信息管理系统 (springboot+vue)
vue.js·spring boot·后端·个人开发·毕设
m0_748229993 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
C澒4 小时前
前端监控系统的最佳实践
前端·安全·运维开发
xiaoxue..4 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
hhy_smile4 小时前
Class in Python
java·前端·python
小邓吖4 小时前
自己做了一个工具网站
前端·分布式·后端·中间件·架构·golang
南风知我意9574 小时前
【前端面试2】基础面试(杂项)
前端·面试·职场和发展
LJianK15 小时前
BUG: Uncaught Error: [DecimalError] Invalid argument: .0
前端