-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vue3 项目中微信小程序调用 wxs 方法无法传入响应式变量作为参数 #4633
Comments
HbuilderX 3.99.2023121601-alpha 可以复现 |
应用下面的补丁修复 diff --git a/node_modules/@dcloudio/uni-mp-compiler/dist/transforms/transformIdentifier.js b/node_modules/@dcloudio/uni-mp-compiler/dist/transforms/transformIdentifier.js
index c674f8b..35eff71 100644
--- a/node_modules/@dcloudio/uni-mp-compiler/dist/transforms/transformIdentifier.js
+++ b/node_modules/@dcloudio/uni-mp-compiler/dist/transforms/transformIdentifier.js
@@ -31,6 +31,38 @@ const transformIdentifier = (node, context) => {
content,
`)`,
]), context);
+ } else {
+ const contentStr = content.children.map((child) => {
+ if (typeof child === 'string') return child
+ if (typeof child.content !== 'string') throw new Error('not support argument')
+ return child.content
+ }).join('')
+ const lhs = contentStr.substring(0, contentStr.indexOf('('))
+ let isLiteral = false
+ for (let i = lhs.length + 1; i < contentStr.length; i++) {
+ if (contentStr[i] === ' ') {
+ continue
+ }
+ if (contentStr[i] === '{' || contentStr[i] === '[') {
+ isLiteral = true
+ break
+ }
+ break
+ }
+
+ const paramStr = contentStr.substring(contentStr.indexOf('(') + 1, contentStr.indexOf(')'))
+ const rewriteParams = isLiteral
+ ? [utils_1.rewriteExpression(compiler_core_1.createCompoundExpression([paramStr]), context)]
+ : paramStr
+ .split(',')
+ .filter((p) => p.trim().length != 0)
+ .map((param) => {
+ return utils_1.rewriteExpression(compiler_core_1.createCompoundExpression([param]), context)
+ })
+ node.content = utils_1.rewriteExpression(
+ compiler_core_1.createCompoundExpression([lhs, '(', ...rewriteParams, ')']),
+ context,
+ )
}
}
else if ((0, compiler_core_1.isSlotOutlet)(node)) {
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
vue3项目在模板中调用 wxs 写的方法运行到微信小程序时传入的参数变成 undefined,运行到 h5 正常。
用 hbuilderx 新建了空白 demo 测试了三种情况:
v-for
遍历响应式数组并把 item 传入 wxs 方法微信小程序 wxs 方法使用参数时对象属性为 undefined
微信小程序不会调用 wxs 方法
都可以正常工作
以下是 demo 代码
复现步骤
预期结果
微信小程序可以正常使用 wxs 方法
实际结果
微信小程序不能正常调用 wxs 方法
log
h5可以正常运行
log
系统信息:
补充信息
demo 是用 hbuilderx 创建的默认模板 vue3 项目
The text was updated successfully, but these errors were encountered: