一、升级版本
优点:方便、一劳永逸
缺点:增加风险,其他使用到基础能力的地方测试需要重新验证一遍
二、使用补丁
手把手教你使用patch-package给npm包打补丁 - 掘金
1、自动
以我的项目为例
Taro版本:3.3.19
打补丁的组件:Button
打补丁的事件:chooseAvatar
需要给一下四个文件添加上对应的方法
- node_modules/@tarojs/components/types/Button.d.ts
/** 获取头像信息
*
* 生效时机:`open-type="chooseAvatar"`
* @supported weapp
*/
onChooseavatar?: CommonEventFunction
- node_modules/@tarojs/plugin-platform-weapp/dist/index.js
bindChooseAvatar:'',
- node_modules/@tarojs/plugin-platform-weapp/dist/runtime.js
- node_modules/@tarojs/plugin-platform-weapp/dist/runtime-utils.js
这两个文件和上面👆的一样
然后运行:
yarn patch-package @tarojs/components
yarn patch-package @tarojs/plugin-platform-weapp
就会自动生成补丁文件
重新yarn install就会发现chooseAvatar方法已经生效了
2、手动
npm i patch-package --save-dev
在src文件夹中创建patchs文件夹包含以下两个文件
文件名:@tarojs+components+3.3.19.patch
内容
diff --git a/node_modules/@tarojs/components/types/Button.d.ts b/node_modules/@tarojs/components/types/Button.d.ts
index 6484cc5..1801546 100644
--- a/node_modules/@tarojs/components/types/Button.d.ts
+++ b/node_modules/@tarojs/components/types/Button.d.ts
@@ -175,6 +175,13 @@ interface ButtonProps extends StandardProps {
*/
onGetRealnameAuthInfo?: CommonEventFunction
+ /** 获取头像信息
+ *
+ * 生效时机:`open-type="chooseAvatar"`
+ * @supported weapp
+ */
+ onChooseavatar?: CommonEventFunction
+
/** 当使用开放能力时,发生错误的回调
*
* 生效时机:`open-type="launchApp"`
@@ -239,6 +246,12 @@ declare namespace ButtonProps {
*/
getPhoneNumber
/** 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 */
+
+ /** 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息
+ * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html
+ */
+ chooseAvatar
+
getUserInfo
/** 用户实名信息授权,已经弃用 */
getRealnameAuthInfo
diff --git a/node_modules/@tarojs/components/types/Input.d.ts b/node_modules/@tarojs/components/types/Input.d.ts
index 1a092d6..121f2da 100644
--- a/node_modules/@tarojs/components/types/Input.d.ts
+++ b/node_modules/@tarojs/components/types/Input.d.ts
@@ -12,7 +12,7 @@ interface InputProps extends StandardProps, FormItemProps {
* @supported weapp, h5, rn
* @rn 部分支持
*/
- type?: 'text' | 'number' | 'idcard' | 'digit'
+ type?: 'text' | 'number' | 'idcard' | 'digit'|'nickname'
/** 是否是密码类型
* @supported weapp, h5, rn
文件名:@tarojs+plugin-platform-weapp+3.3.19.patch
内容
diff --git a/node_modules/@tarojs/plugin-platform-weapp/dist/index.js b/node_modules/@tarojs/plugin-platform-weapp/dist/index.js
index c991fd7..e989428 100644
--- a/node_modules/@tarojs/plugin-platform-weapp/dist/index.js
+++ b/node_modules/@tarojs/plugin-platform-weapp/dist/index.js
@@ -121,6 +121,7 @@ const components = {
'business-id': '',
bindGetUserInfo: '',
bindContact: '',
+ bindChooseAvatar:'',
bindGetPhoneNumber: '',
bindError: '',
bindOpenSetting: '',
diff --git a/node_modules/@tarojs/plugin-platform-weapp/dist/runtime-utils.js b/node_modules/@tarojs/plugin-platform-weapp/dist/runtime-utils.js
index 2c5c1c1..9125cec 100644
--- a/node_modules/@tarojs/plugin-platform-weapp/dist/runtime-utils.js
+++ b/node_modules/@tarojs/plugin-platform-weapp/dist/runtime-utils.js
@@ -77,6 +77,7 @@ const components = {
'business-id': '',
bindGetUserInfo: '',
bindContact: '',
+ bindChooseAvatar:'',
bindGetPhoneNumber: '',
bindError: '',
bindOpenSetting: '',
diff --git a/node_modules/@tarojs/plugin-platform-weapp/dist/runtime.js b/node_modules/@tarojs/plugin-platform-weapp/dist/runtime.js
index 4b3ce00..b3b847c 100644
--- a/node_modules/@tarojs/plugin-platform-weapp/dist/runtime.js
+++ b/node_modules/@tarojs/plugin-platform-weapp/dist/runtime.js
@@ -75,6 +75,7 @@ const components = {
'app-parameter': '',
'show-message-card': 'false',
'business-id': '',
+ bindChooseAvatar:'',
bindGetUserInfo: '',
bindContact: '',
bindGetPhoneNumber: '',
package.json
在启动命名中添加
"postinstall": "patch-package"