(文章目录)

一、前言

vue实例属性$options用来获取定义在data外的数据和方法。

应用示例如下:

<script>
export default {
  name: "optionsTest",
  data() {
    return {
    };
  },
  //在data外面定义的属性和方法通过$options可以获取和调用
  name: "CSDN",
  age: 12,
  testMethod() {
    console.log("shq5785");
  },
  created() {  
    console.log(this.$options.name);  // CSDN
    console.log(this.$options.age);  //12
    this.$options.testMethod();  // shq5785
  
  },
</script>

二、拓展阅读

  • 《Vue系列》