How vuejs creates and calls global methods
This article mainly introduces vuejs how to create and call global methods, the article is very detailed, has a certain reference value, interested friends must read it!
Create and call a global method: 1, customize a method under any file in the src directory of the vue project; 2, introduce a custom method using the importstatement in the "main.js" file, and mount the method on the vue instance; 3, in the required page, use the "$vue instance. Method name ()" statement to call the method.
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.
Vue.js creates and calls global methods
In the vue project, first customize a method under any file in src, as an example
TransNum (num) {if (typeof (num) = 'undefined') {return 0} else {let oldNum = num.toString () .trim () let len = oldNum.length if (len