The problem of vue calling parent components and calling child components

< income: getStandards= "getStandards": index= "index" ref= "refIncome" > < / income >

clickPurchase: function (index) {

   this.$refs.refIncome.handleStatePromptContent()

}
this is a child component referenced by the parent component

handleStatePromptContent () {

  if ((this.$parent.details.isFirst === 0) && (this.$parent.details.isNovice === 1)) {
  // this.showDialog = true
  // this.message = ""
  this.statePromptContent = ""
  return false
  }
  if ((this.$parent.details.isNovice === 1) && (this.Total > 50000)) {
  // this.showDialog = true
  this.statePromptContent = "50000"
  // this.message = "50000"
  return false
  }
  if (this.count <= 0) {
  // this.showDialog = true
  this.statePromptContent = ""
  // this.message = ""
  return false
  }
}


clipboard.png
then this error is reported. Ask for advice on what"s going on.

Mar.29,2021

there is no problem with calling subcomponents in this way, but an error has been reported. Is it because your subcomponent method is not correctly placed in methods? it is recommended that you follow the breakpoint to see if this.$refs.refIncome points to the vue instance object of the corresponding subcomponent (some of the properties in it help you confirm), and then see if this method exists in this instance object.


handleStatePromptContent this is the method in the component. This.$refs.refIncome refers to a dom object. How can the dom object call the method of the component?


it is recommended that you do not use this way for the parent component to call the method of the child component. It is recommended to use custom events, that is, the child component listens for an event in the mounted hook function this.$on , and then triggers that event to this.$emit when needed by the parent component.
also, it is best to use a more disciplined way to pass values between parent and child components, instead of directly this.$parent.details.isNovice to obtain values. Vue is data-driven rather than directly manipulating dom.

Menu