• 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

Code Notes barben 2 months ago (05-29) 137 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.
Can I manage all the rules together? So I did these things

Create a JS file

You can put this JS file 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

Import this JS 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

 console.log(this.$rules.loginRules);

summary

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


We've been blogging that year
If the article and the author are not noted, please reprint it
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