• Welcome to the eight year blog, I'm glad to meet you at the right age!
  • Due to the theme, QQ login partners will display the default avatar in the comments. Please go to the personal center and upload the avatar again.

Vue modularizes data, such as element form verification

Note code barben 6 months ago (05-29) 351 views 0 comments

Why modularize data?

Today, when using the form component of element, I saw that the form verification rules were written under the data of the page, which was very messy.
So I wonder, can we put all the rules of form verification together for easy management? So I did these things

Create a JS file

JS can be placed anywhere you want in the project.

Then, in this JS file, write your data, and use export default to expose the data, as follows:

 Export default your data

JS import this file

Use import.
You can introduce it on the page you need. Or you can introduce it in main. JS and mount it globally

 import rules from './assets/js/rules'
Vue.prototype.$rules = rules;

Use this data

You can directly call this. $rules to read the content that you exposed in the JS file



Whether you want to unify the management of data or methods, you can use this method to achieve, easy to find and modify later.

Eight blogs that year, we've been there all the time
If the author does not indicate the original article, please indicate the link and source of this article
Vue modularizes data, such as element form verification - https://www.barben.cn/code/836.html
Like it( eight )
Post my comments
Cancel comment
expression Mapping Bold Strikethrough Center Italics

You need to bring your nickname and email with you in the year of eight!

  • Nickname (required)
  • Email address (required)
  • website