SoFunction
Updated on 2025-04-05

How to solve the problem of this.$ not executing

This.$() does not execute problem

question

When using the following method to obtain the verification status, it cannot be obtained, and console has no result output

this.$().then(valid => {
  (valid)
})

reason

①There is a prop without adding the verification rules

For example: I wrote many such props in the code as fields that need to be verified:

<FormItem label="URL Filtering" prop="groupId">

However, the prop does not appear in the defined rules:

rules: {
  schemaId: [{ required: true, message: 'Required'}],
}

Note: Generally speaking, adding more props will not cause problems, and it may be that there are problems with custom verification.

② There is no callback() in the custom verification rule

For example: If the value is not verified to be empty:

    const validateFilter = (rule, value, callback) => {
     if (!(item => HTTPHEADER_KEYWORD_REGEXP.test(item))) {
        callback(new Error('Keyword format error: each with a maximum length of 255 characters, cannot contain Chinese'))
      } else if (('').length > 2048) {
        callback(new Error('Error: The total length cannot exceed 2048 characters'))
      } else {
        callback()
      }
    }

The above judgment does not take into account that the value is empty and callback() must be executed once, so the check status is not executed when the value is empty.

    const validateFilter = (rule, value, callback) => {
      if (!value) {
        callback()
      } else if (!(item => HTTPHEADER_KEYWORD_REGEXP.test(item))) {
        callback(new Error('Keyword format error: each with a maximum length of 255 characters, cannot contain Chinese'))
      } else if (('').length > 2048) {
        callback(new Error('Error: The total length cannot exceed 2048 characters'))
      } else {
        callback()
      }
    }

Solution:

  • Check code writing specifications according to the framework documentation
  • Print this.$() and look at the status. If the status is pedding (to-do), and the execution has not been completed yet, continue to look at the verification rules issue and whether you consider the situation where callback() is fully implemented.

this.$() does not work

Question description?

When using this method to obtain the verification status, it cannot be obtained and console has no result output

this.$().then((valid) => {
    (valid)
});

Solution

Remove the props that have not been added to the verification rules

What does it mean?

I've written a lot of such props in my code as fields that need verification

<FormItem label="Cross-network gateway" prop="groupId">

However, the prop does not appear in the rules I defined

rules: {
   schemaId: [{required: true, message: 'Required'}],
},

Solution

Because I use the ivew framework, I will first check it out on the ivew official website. Generally, some simple problems can be solved by just browsing the official website. However, my nonsensical problems are obvious. I have not gained any substantial gains on the official website.

When you go to Baidu, even if you can’t get any substantial solutions from your predecessors or peers, you can at least broaden your mind.

I'll tell you what I'll gain:

Make sure that the custom rules are called back() callback at the end

You can print this.$() yourself to see the status

Although it seems that there is no substantial solution to it, I understand from it that my verification must have not been completed and I will not say much.

(this.$())

As expected, my state is pedding (to-do) state, and the execution has not been completed yet. At this time, I continue to check to ensure that there is no problem with the verification rules. Then I can only be the above. I have defined more prop fields myself, and after removing them, it is normal.

Generally speaking, there will be no problem with adding more props. It may be that there is a problem with your custom verification (it may be that your custom rules do not write callback(), check it).

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.