Home >WeChat Applet >WeChat Development >Detailed explanation of examples of referencing other js files in WeChat development

Detailed explanation of examples of referencing other js files in WeChat development

零下一度
零下一度Original
2017-05-26 10:37:122139browse

This article mainly introduces the WeChat appletQuoteOther js file implementation code related information, friends in need can refer to

WeChat How does a small program reference other js files

1. We first create a common.js file and write our program in common.js,

function myfunc() {
console.log("myfunc....");
}

module.exports.myfunc = myfunc; This exposes interface. It cannot be referenced if it is not exposed here.

is in the file domain js Inside

var common = require("../../common.js"); to link over, just linking over is not enough!

 var app;
var common = require("../../common.js");
Page({
data:{

},
onLoad:function() {
app = getApp();
this.setData({version:app.globalData.appName});
common.myfunc(); //最后我们需要执行才能生效!
}
})

[Related recommendations]

1. How to call global JS in WeChat development?

2. JS dynamic modification style of WeChat development

3. Example tutorial of life cycle function of WeChat development

The above is the detailed content of Detailed explanation of examples of referencing other js files in WeChat development. 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