How does a .vue single-file component usually call an instance method?

where should I write an instance method such as vm.$watch if I want to call it?

<script>
export default {
  name: "componentA",
  data () {
      /*****/
  },
  methods: {
    methodA: function () {
      /*****/
    }
  }
};
</script>
Mar.09,2021

if you are not clicking, you can write it directly in computed or life cycle, but it is not recommended that created, use mounted


<script>
export default {
  name: 'componentA',
  data () {
    text: '123',
      /*****/
  },
  watch: {
    text() {
        console.log(text)
    }
  }
  methods: {
    methodA: function () {
      /*****/
    }
  }
};
</script>

because it cannot perform dom operation.

can be adjusted in methods, computed, or lifecycle hook functions. In principle, you can access the this (vm) instance anywhere.

<script>
export default {
  name: 'componentA',
  data () {
      /*****/
      param:'test'
  },
  computed:{
      param2(val){
         // 
         this.$set('param', val)
         return val + this.param
      }
  },
  created(){
      // 
      this.$watch('param',(n,o) => {})
  },
  methods: {
    methodA: function () {
      /*****/
      // methods
      this.$watch('param',(n,o) => {})
    }
  }
};
</script>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e59307-4550a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e59307-4550a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?