Skip to content

Commit f3b71c8

Browse files
committed
fix(uni-mp-xhs): 解决小红书平台自定义组件问题
1 parent 516410a commit f3b71c8

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

packages/uni-mp-vue/dist/vue.runtime.esm.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -7106,7 +7106,7 @@ function setRef$1(instance, isUnmount = false) {
71067106
(templateRef) => setTemplateRef(templateRef, null, setupState)
71077107
);
71087108
}
7109-
const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao";
7109+
const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao" || $mpPlatform === "mp-xhs";
71107110
const doSetByRefs = (refs) => {
71117111
const mpComponents = (
71127112
// 字节小程序 selectAllComponents 可能返回 null
@@ -7774,13 +7774,19 @@ function vOn(value, key) {
77747774
const instance = getCurrentInstance();
77757775
const ctx = instance.ctx;
77767776
// 微信小程序,QQ小程序,当 setData diff 的时候,若事件不主动同步过去,会导致事件绑定不更新,(question/137217)
7777-
const extraKey = typeof key !== 'undefined' &&
7778-
(ctx.$mpPlatform === 'mp-weixin' ||
7779-
ctx.$mpPlatform === 'mp-qq' ||
7780-
ctx.$mpPlatform === 'mp-xhs') &&
7777+
let extraKey = typeof key !== 'undefined' &&
7778+
(ctx.$mpPlatform === 'mp-weixin' || ctx.$mpPlatform === 'mp-qq') &&
77817779
(isString(key) || typeof key === 'number')
77827780
? '_' + key
77837781
: '';
7782+
// 解决小红书平台可能出现自定义组件事件错乱问题
7783+
// @ts-expect-error: ctx.$mpType
7784+
const needExtraKey = ctx.$mpPlatform === 'mp-xhs' && ctx.$mpType === 'component';
7785+
const eiCounter = instance.$ei++;
7786+
if (needExtraKey) {
7787+
// @ts-expect-error: ctx.componentId
7788+
extraKey = '_' + ctx.componentId + '_' + eiCounter;
7789+
}
77847790
const name = 'e' + instance.$ei++ + extraKey;
77857791
const mpInstance = ctx.$scope;
77867792
if (!value) {

packages/uni-mp-vue/lib/vue.runtime.esm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4744,7 +4744,7 @@ function setRef(instance, isUnmount = false) {
47444744
(templateRef) => setTemplateRef(templateRef, null, setupState)
47454745
);
47464746
}
4747-
const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao";
4747+
const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao" || $mpPlatform === "mp-xhs";
47484748
const doSetByRefs = (refs) => {
47494749
const mpComponents = (
47504750
// 字节小程序 selectAllComponents 可能返回 null

packages/uni-mp-vue/src/helpers/vOn.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ export function vOn(value: EventValue | undefined, key?: number | string) {
2727
}
2828
const ctx = instance.ctx
2929
// 微信小程序,QQ小程序,当 setData diff 的时候,若事件不主动同步过去,会导致事件绑定不更新,(question/137217)
30-
const extraKey =
30+
let extraKey =
3131
typeof key !== 'undefined' &&
32-
(ctx.$mpPlatform === 'mp-weixin' ||
33-
ctx.$mpPlatform === 'mp-qq' ||
34-
ctx.$mpPlatform === 'mp-xhs') &&
32+
(ctx.$mpPlatform === 'mp-weixin' || ctx.$mpPlatform === 'mp-qq') &&
3533
(isString(key) || typeof key === 'number')
3634
? '_' + key
3735
: ''
3836

37+
// 解决小红书平台可能出现自定义组件事件错乱问题
38+
const needExtraKey =
39+
// @ts-expect-error: ctx.$mpType
40+
ctx.$mpPlatform === 'mp-xhs' && ctx.$mpType === 'component'
41+
const eiCounter = instance.$ei++
42+
if (needExtraKey) {
43+
// @ts-expect-error: ctx.componentId
44+
extraKey = '_' + ctx.componentId + '_' + eiCounter
45+
}
46+
3947
const name = 'e' + instance.$ei++ + extraKey
4048

4149
const mpInstance = ctx.$scope

0 commit comments

Comments
 (0)