Fix: migrating config not compatible with camel case props and events (#15260)

pull/15269/head
Simona 2019-04-25 16:59:18 +08:00 committed by hetech
parent 5d58acac5c
commit 959b7b4698
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { kebabCase } from 'element-ui/src/utils/util';
/**
* Show migrating guide in browser console.
*
@ -29,13 +30,15 @@ export default {
const definedEvents = componentOptions.listeners || {};
for (let propName in definedProps) {
if (definedProps.hasOwnProperty(propName) && props[propName]) {
propName = kebabCase(propName); // compatible with camel case
if (props[propName]) {
console.warn(`[Element Migrating][${this.$options.name}][Attribute]: ${props[propName]}`);
}
}
for (let eventName in definedEvents) {
if (definedEvents.hasOwnProperty(eventName) && events[eventName]) {
eventName = kebabCase(eventName); // compatible with camel case
if (events[eventName]) {
console.warn(`[Element Migrating][${this.$options.name}][Event]: ${events[eventName]}`);
}
}

View File

@ -135,3 +135,11 @@ export const autoprefixer = function(style) {
});
return style;
};
export const kebabCase = function(str) {
const hyphenateRE = /([^-])([A-Z])/g;
return str
.replace(hyphenateRE, '$1-$2')
.replace(hyphenateRE, '$1-$2')
.toLowerCase();
};