Vue高阶技巧-利用工具方法defineReactive数据前置响应

<script>
import Vue from "vue";
const proto = Vue.prototype;
const defineReactive = Vue.util.defineReactive;

const alphaData = {
  string: "string",
  number: 1,
  boolean: true,
  array: ["str", 1, true],
  obj: {
    o1: "o1",
    o2: {
      a: 1
    }
  }
};

defineReactive(proto, "$alphaData", alphaData);

export default {
  created() {
    console.log(this.$alphaData); // alphaData = {}
  }
};
</script>
发布时间:2019-08-28
目录