特易招,招聘小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

4 months ago
  1. export default {
  2. data() {
  3. return {
  4. }
  5. },
  6. methods: {
  7. // 设置数据
  8. setData: function(obj, callback) {
  9. let that = this;
  10. const handleData = (tepData, tepKey, afterKey) => {
  11. tepKey = tepKey.split('.');
  12. tepKey.forEach(item => {
  13. if (tepData[item] === null || tepData[item] === undefined) {
  14. let reg = /^[0-9]+$/;
  15. tepData[item] = reg.test(afterKey) ? [] : {};
  16. tepData = tepData[item];
  17. } else {
  18. tepData = tepData[item];
  19. }
  20. });
  21. return tepData;
  22. };
  23. const isFn = function(value) {
  24. return typeof value == 'function' || false;
  25. };
  26. Object.keys(obj).forEach(function(key) {
  27. let val = obj[key];
  28. key = key.replace(/\]/g, '').replace(/\[/g, '.');
  29. let front, after;
  30. let index_after = key.lastIndexOf('.');
  31. if (index_after != -1) {
  32. after = key.slice(index_after + 1);
  33. front = handleData(that, key.slice(0, index_after), after);
  34. } else {
  35. after = key;
  36. front = that;
  37. }
  38. if (front.$data && front.$data[after] === undefined) {
  39. Object.defineProperty(front, after, {
  40. get() {
  41. return front.$data[after];
  42. },
  43. set(newValue) {
  44. front.$data[after] = newValue;
  45. that.$forceUpdate();
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. front[after] = val;
  51. } else {
  52. that.$set(front, after, val);
  53. }
  54. });
  55. // this.$forceUpdate();
  56. isFn(callback) && this.$nextTick(callback);
  57. },
  58. }
  59. }