main.js 1.8 KB

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