From 1402eaa4f41426af2d80d67d098871d51ceb722c Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 20 Jan 2020 16:44:12 +0800 Subject: [PATCH] fix(mp): hyphenate component name (easycom) --- packages/uni-template-compiler/lib/app/view.js | 2 +- packages/uni-template-compiler/lib/auto-components.js | 4 +++- packages/uni-template-compiler/lib/script/traverse/visitor.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/uni-template-compiler/lib/app/view.js b/packages/uni-template-compiler/lib/app/view.js index 2d99b5bc5..46242f920 100644 --- a/packages/uni-template-compiler/lib/app/view.js +++ b/packages/uni-template-compiler/lib/app/view.js @@ -209,7 +209,7 @@ function handleViewEvents (events) { function genVModel (el, isScopedSlot) { if (el.model) { el.model.value = createGenVar(el.attrsMap[ID], isScopedSlot)('v-model', el.model.value) - if (el.tag === 'v-uni-input' || el.tag === 'v-uni-textarea' && !(el.events && el.events.input)) { + if ((el.tag === 'v-uni-input' || el.tag === 'v-uni-textarea') && !(el.events && el.events.input)) { el.model.callback = `function($$v){$handleVModelEvent(${el.attrsMap[ID]},$$v)}` } else { el.model.callback = `function(){}` diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js index cc9966cd8..e01d111f6 100644 --- a/packages/uni-template-compiler/lib/auto-components.js +++ b/packages/uni-template-compiler/lib/auto-components.js @@ -1,6 +1,7 @@ const path = require('path') const { + hyphenate, isComponent } = require('./util') @@ -44,7 +45,8 @@ function updateMPUsingAutoImportComponents (autoComponents, options) { name, source }) => { - usingAutoImportComponents[name] = '/' + formatSource(source) + // 自定义组件统一格式化为 kebab-case + usingAutoImportComponents[hyphenate(name)] = '/' + formatSource(source) }) updateUsingAutoImportComponents(resourcePath, usingAutoImportComponents) // 更新json } diff --git a/packages/uni-template-compiler/lib/script/traverse/visitor.js b/packages/uni-template-compiler/lib/script/traverse/visitor.js index f7bbb7c12..6da1f3fc7 100644 --- a/packages/uni-template-compiler/lib/script/traverse/visitor.js +++ b/packages/uni-template-compiler/lib/script/traverse/visitor.js @@ -59,7 +59,7 @@ function addVueId (path, state) { state.options.$vueId = 1 } const hashId = state.options.hashId - const vueId = String((hashId ? (hashId + '-') : '') + (state.options.$vueId++)) + const vueId = (hashId ? (hashId + '-') : '') + (state.options.$vueId++) let value -- GitLab