Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

js require的问题?

在微信小程序的开发中,我写了这样的代码

//requesting.js
function requesting() {
}

module.exports = {
    requesting: requesting
}
// path.js
const requesting = require('../../../requesting')

module.exports = {
    requesting: requesting
}
// example.js
const path = require('../../path')
const requesting = path.requesting

这个写没有问题吧, 因为require只能写相对路径,我加入一个path.js的目的就是为了记录那些经常使用的js文件的路径,这样在引入的时候我就只需要引入path.js的路径就可以了. 但是在微信小程序中却提示我找不到requesting这个函数, 但是如果直接引用require (requesting)是可以的这,让我很疑惑, 这是为什么?
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

image.png

按你这写法应该是

const requesting = path.requesting.requesting

才对。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...