a17c09c2a77763165dbee04f1833e85f6d4da4e4601132869e973a2790a9bb8c8f01412f98afbd7f4abb060622b81cb873e49ec89f980c61f65c9d3e92e400 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { 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. */
  23. export 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. for (let propName in definedProps) {
  32. propName = kebabCase(propName); // compatible with camel case
  33. if (props[propName]) {
  34. console.warn(`[Element Migrating][${this.$options.name}][Attribute]: ${props[propName]}`);
  35. }
  36. }
  37. for (let eventName in definedEvents) {
  38. eventName = kebabCase(eventName); // compatible with camel case
  39. if (events[eventName]) {
  40. console.warn(`[Element Migrating][${this.$options.name}][Event]: ${events[eventName]}`);
  41. }
  42. }
  43. },
  44. methods: {
  45. getMigratingConfig() {
  46. return {
  47. props: {},
  48. events: {}
  49. };
  50. }
  51. }
  52. };