vue project, a lot of different methods and then components will be reused, such as phone number format ah password authentication, etc., are reusable, and so want to extract these common methods, many online methods, the following method effective pro-test , record it
The first step: to build a common approach js file, I put this file on a static following js folder inside ~ write a test method
The second step: the introduction method in main.js
import commonFunction from '../static/js/commonFunction' Vue.prototype.commonFunction = commonFunction ;
The third step: using a common method requires the use of the component
created(){ this.commonFunction.testFunction(); },