support v-show

This commit is contained in:
Amour1688 2020-05-23 16:38:53 +08:00
parent f413253ff8
commit 4667679054

View File

@ -111,6 +111,11 @@ const transformJSXAttribute = (path, attributesToMerge, directives, injected) =>
: name.replace(`v${name[1]}`, name[1].toLowerCase()); : name.replace(`v${name[1]}`, name[1].toLowerCase());
if (directiveName === '_model') { if (directiveName === '_model') {
directives.push(getJSXAttributeValue(path)); directives.push(getJSXAttributeValue(path));
} else if (directiveName === 'show') {
directives.push(t.arrayExpression([
injected.vShow,
getJSXAttributeValue(path),
]));
} else { } else {
directives.push(t.arrayExpression([ directives.push(t.arrayExpression([
t.callExpression(injected.resolveDirective, [ t.callExpression(injected.resolveDirective, [
@ -323,12 +328,16 @@ module.exports = () => ({
if (!state.vueResolveDirectiveInjected) { if (!state.vueResolveDirectiveInjected) {
state.vueResolveDirectiveInjected = addNamed(path, 'resolveDirective', 'vue'); state.vueResolveDirectiveInjected = addNamed(path, 'resolveDirective', 'vue');
} }
if (!state.vueVShowInjected) {
state.vueVShowInjected = addNamed(path, 'vShow', 'vue');
}
path.replaceWith( path.replaceWith(
transformJSXElement(path, { transformJSXElement(path, {
h: state.vueCreateElementInjected, h: state.vueCreateElementInjected,
mergeProps: state.vueMergePropsInjected, mergeProps: state.vueMergePropsInjected,
withDirectives: state.vueWithDirectivesInjected, withDirectives: state.vueWithDirectivesInjected,
resolveDirective: state.vueResolveDirectiveInjected, resolveDirective: state.vueResolveDirectiveInjected,
vShow: state.vueVShowInjected,
}), }),
); );
}, },