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
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
You can import 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.