main.js 1.8 KB

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