Get the App
SLTechnology News&Howtos  ›  Development  › 

How vuejs creates and calls global methods

Shulou Source: shulou.com Published: 2022-06-03 09:45:25 11月15日 Update

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

Tags: Method file global instance method content project article statement and will code value interest reason cycle partner tutorial more environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia MariaDB Huawei vpn