Home  >  Article  >  Web Front-end  >  How uniapp encapsulates public methods

How uniapp encapsulates public methods

coldplay.xixi
coldplay.xixiOriginal
2020-12-08 16:34:238135browse

Implement the common method of uniapp encapsulation: first create uni-app and create a new page file; then create a new encapsulation file and define the encapsulation method; then call the method on the page; finally save the compilation preview.

How uniapp encapsulates public methods

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.

Recommended (free):uni-app development tutorial

Implementing uniapp encapsulation public methods:

1. Double-click to open the HBuilderX development tool, create the uni-app project and open it

How uniapp encapsulates public methods

2. Under the pages folder, create a new page file index .vue, and open

How uniapp encapsulates public methods

3, create a utils folder, and then create a new JavaScript file DateUtils.js

How uniapp encapsulates public methods

4. Open the newly created js file, define the function statusTime, and then return the date in the specified format

How uniapp encapsulates public methods

5. In the index.vue file, insert a picker element and bind it Properties and variables

How uniapp encapsulates public methods

6. In the <script></script> tag, import DateUtils and use

in the variable

How uniapp encapsulates public methods

7. Save the code and compile the code. Check the compilation effect in WeChat developer tools

How uniapp encapsulates public methods

Related free learning Recommended: Programming Video

The above is the detailed content of How uniapp encapsulates public methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn