main.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import Vue from 'vue';
  2. import App from './App';
  3. import contactButton from "@/components/contact-button/index";
  4. import updateUserinfo from '@/components/update-userinfo/index';
  5. import toUserinfo from '@/components/to-userinfo/index';
  6. import updateUserinfonew from '@/components/update-userinfonew/index';
  7. Vue.config.productionTip = false;
  8. Vue.component("contact-button", contactButton);
  9. Vue.component("update-userinfo", updateUserinfo);
  10. Vue.component("to-userinfo", toUserinfo);
  11. Vue.component("update-userinfonew", updateUserinfonew);
  12. Vue.mixin({
  13. methods: {
  14. setData: function(obj, callback) {
  15. let that = this;
  16. const handleData = (tepData, tepKey, afterKey) => {
  17. tepKey = tepKey.split('.');
  18. tepKey.forEach(item => {
  19. if (tepData[item] === null || tepData[item] === undefined) {
  20. let reg = /^[0-9]+$/;
  21. tepData[item] = reg.test(afterKey) ? [] : {};
  22. tepData = tepData[item];
  23. } else {
  24. tepData = tepData[item];
  25. }
  26. });
  27. return tepData;
  28. };
  29. const isFn = function(value) {
  30. return typeof value == 'function' || false;
  31. };
  32. Object.keys(obj).forEach(function(key) {
  33. let val = obj[key];
  34. key = key.replace(/\]/g, '').replace(/\[/g, '.');
  35. let front, after;
  36. let index_after = key.lastIndexOf('.');
  37. if (index_after != -1) {
  38. after = key.slice(index_after + 1);
  39. front = handleData(that, key.slice(0, index_after), after);
  40. } else {
  41. after = key;
  42. front = that;
  43. }
  44. if (front.$data && front.$data[after] === undefined) {
  45. Object.defineProperty(front, after, {
  46. get() {
  47. return front.$data[after];
  48. },
  49. set(newValue) {
  50. front.$data[after] = newValue;
  51. that.$forceUpdate();
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. front[after] = val;
  57. } else {
  58. that.$set(front, after, val);
  59. }
  60. });
  61. // this.$forceUpdate();
  62. isFn(callback) && this.$nextTick(callback);
  63. }
  64. }
  65. });
  66. App.mpType = 'app';
  67. const app = new Vue({
  68. ...App
  69. });
  70. app.$mount();