UNPKG

1.54 kBJavaScriptView Raw
1import { kebabCase } from 'element-ui/src/utils/util';
2/**
3 * Show migrating guide in browser console.
4 *
5 * Usage:
6 * import Migrating from 'element-ui/src/mixins/migrating';
7 *
8 * mixins: [Migrating]
9 *
10 * add getMigratingConfig method for your component.
11 * getMigratingConfig() {
12 * return {
13 * props: {
14 * 'allow-no-selection': 'allow-no-selection is removed.',
15 * 'selection-mode': 'selection-mode is removed.'
16 * },
17 * events: {
18 * selectionchange: 'selectionchange is renamed to selection-change.'
19 * }
20 * };
21 * },
22 */
23export default {
24 mounted() {
25 if (process.env.NODE_ENV === 'production') return;
26 if (!this.$vnode) return;
27 const { props = {}, events = {} } = this.getMigratingConfig();
28 const { data, componentOptions } = this.$vnode;
29 const definedProps = data.attrs || {};
30 const definedEvents = componentOptions.listeners || {};
31
32 for (let propName in definedProps) {
33 propName = kebabCase(propName); // compatible with camel case
34 if (props[propName]) {
35 console.warn(`[Element Migrating][${this.$options.name}][Attribute]: ${props[propName]}`);
36 }
37 }
38
39 for (let eventName in definedEvents) {
40 eventName = kebabCase(eventName); // compatible with camel case
41 if (events[eventName]) {
42 console.warn(`[Element Migrating][${this.$options.name}][Event]: ${events[eventName]}`);
43 }
44 }
45 },
46 methods: {
47 getMigratingConfig() {
48 return {
49 props: {},
50 events: {}
51 };
52 }
53 }
54};