Skip to content

Commit dbf33a3

Browse files
committed
修复 未映射
1 parent b5946ad commit dbf33a3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/vue-to-horizon/libs/horizon-vue/src/next/convert/jsx/handlers/expressionHandler.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,29 @@ export function createNodeByVueVariable(name, reactCovert, path) {
206206
// 处理特殊的 $ 开头的属性
207207
else if (name.startsWith('$')) {
208208
switch (name) {
209+
case '$emit': {
210+
// 将模板中的 $emit(...) 统一映射为 emit(...)
211+
// 若不存在 emit,则自动注入: const emit = defineEmits(props);
212+
reactCovert.sourceCodeContext.addExtrasImport('defineEmits', globalLibPaths.vue);
213+
reactCovert.addCodeAstToHorizonForOnce('emit', () => {
214+
return t.variableDeclaration('const', [
215+
t.variableDeclarator(
216+
t.identifier('emit'),
217+
t.callExpression(t.identifier('defineEmits'), [t.identifier(reactCovert.sourceCodeContext.propsName)])
218+
),
219+
]);
220+
});
221+
return t.identifier('emit');
222+
}
223+
case '$store':
224+
// 处理 Vuex store
225+
reactCovert.sourceCodeContext.addExtrasImport('useStore', globalLibPaths.vuex.path);
226+
reactCovert.addCodeAstToHorizonForOnce('useStore', () => {
227+
return t.variableDeclaration('const', [
228+
t.variableDeclarator(t.identifier(name), t.callExpression(t.identifier('useStore'), [])),
229+
]);
230+
});
231+
return t.identifier(name);
209232
case '$store':
210233
// 处理 Vuex store
211234
reactCovert.sourceCodeContext.addExtrasImport('useStore', globalLibPaths.vuex.path);

0 commit comments

Comments
 (0)