码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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"
    	}
    },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    main.js文件中引入插件

    // 引入全局uview-plus
     import uviewPlus from './uni_modules/uview-plus/index.js'
    
     const app = createSSRApp(App)
     app.use(uviewPlus)
     
     return {
      app
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    TS相关
    创建env.d.ts

    declare module '@/uni_modules/uview-plus';
    
    • 1

    并写入tsconfig.json

    {	
    	"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    	"typeRoots": [
    		"@/env.d.ts"
    	]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    遇到的问题

    我的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  
        }  
      }  
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

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

  • 相关阅读:
    flarum 论坛 User Statistics插件修改
    网络通信IO模型上
    软考 系统架构设计师系列知识点之基于架构的软件开发方法ABSD(1)
    macOS 和 Linux 有什么区别?
    Java——Map,Set
    树莓派开发笔记(十七):树莓派4B+上Qt多用户连接操作Mysql数据库同步(单条数据悲观锁)
    C++ 64位系统常见数据类型及大小 (Visual Studio && GCC x64)
    windows11配置电脑IP
    vue3中使用vue-echarts
    100.一个linux内核选项对ssh的影响
  • 原文地址:https://blog.csdn.net/yuemitengfeng/article/details/136194288
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号