-
Notifications
You must be signed in to change notification settings - Fork 382
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
Bugfix: 输出 web externalClasses功能修复 #1661
Conversation
@@ -5,5 +5,6 @@ module.exports = { | |||
RESOLVE_IGNORED_ERR: new Error('Resolve ignored!'), | |||
JSON_JS_EXT: '.json.js', | |||
MPX_ROOT_VIEW: 'mpx-root-view', // 根节点类名 | |||
MPX_APP_MODULE_ID: 'mpx-app-scope' // app文件moduleId | |||
MPX_APP_MODULE_ID: 'mpx-app-scope', // app文件moduleId | |||
P_MODULE_ID: 'p-module-id' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成__pid吧
const dynamicClass = getAndRemoveAttr(el, ':' + className).val | ||
if (dynamicClass) { | ||
attrValue = dynamicClass | ||
attrName = ':' + className |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这还给他覆盖了。。。会出bug。。。
不用getAndRemove,你就检查一下attrsMap中有就行。。。
const reg = new RegExp('\\b' + className + '\\b', 'g') | ||
const replacementClassName = dash2hump(className) | ||
const replacementModuleId = dash2hump(P_MODULE_ID) | ||
classLikeAttrValue = classLikeAttrValue.replace(reg, `{{${replacementClassName}||''}} {{${replacementModuleId}}}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这不用每次替换都扔一个moduleId啊
name: 'class', | ||
value: classNames.join(' ') | ||
name: ':' + classLikeAttrName, | ||
value: `['${classNames.join(' ')}', ${replacements.join(' ')}, $attrs[${stringify(P_MODULE_ID)}]].join(' ')` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[${classname},${replacements}].join(' ')
if (dynamicClass) replacements.push(dynamicClass) | ||
|
||
} else if (classNames.length) { | ||
// 静态class拼接 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全走动态就可以
if (staticClass) { | ||
const classNames = staticClass.split(/\s+/) | ||
function processWebClass (classLikeAttrName, classLikeAttrValue, el, options) { | ||
const classNames = classLikeAttrValue.split(/\s+/) | ||
const replacements = [] | ||
options.externalClasses.forEach((className) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classNames = classNames.map((className)=>{
if(extenalClasses.includes(className)) return `($attrs[${stringify(className)}] || '')`
return stringify(className)
})
classNames.push(`($attrs[${stringify(PMID)}] || '')`)
value = `[${classNames}].join(' ')`
}]) | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要拆这么开,
if(classLikeAttrName === 'class') {
const dynamicClass = getAndRemoveAttr(el, ':class').val
if (dynamicClass) classNames.push(dynamicClass)
addAttrs(el, [{
name: ':class',
value: `[${classNames}]`
}])
} else {
addAttrs(el, [{
name: ':' + classLikeAttrName,
value: `[${classNames}].join(' ')`
}])
}
调整输出web externalClasses实现逻辑,完全走Mpx内部处理,不再经由vue处理