微信小程序的index.js怎么写?详细代码见下方↓

JavaScript06

微信小程序的index.js怎么写?详细代码见下方↓,第1张

微信小程序实例index.js代码如下:可以搜索小程序名称: 快递最后一公里实例index.js代码var app = getApp()Page({/*** 页面的初始数据*/data: { //三张图片轮播imgUrls: [{imageUrl: '/images/weicha/timg1.jpg',},{imageUrl: '/images/weicha/timg2.jpg',},{imageUrl: '/images/weicha/timg3.jpg',}],indicatorDots: false,autoplay: false,interval: 5000,duration: 800,},onSwiperTab: function (e) {/*var postId = e.target.dataset.postIdwx.navigateTo({url: postId,})*/}, /*** 生命周期函数--监听页面加载*/onLoad: function (options) {app.loginWinCha(this.initPageData)},//初始化登录才能查看的数据initPageData: function () {this.setData({componentList: [{id: 1,url: '../weicha/express/courier/index',imageUrl: '/images/weicha/timg1_1.jpg',title: '快递小哥(送快递)',queryType: 'courier'},{id: 2,url: '../weicha/express/seller/index',imageUrl: '/images/weicha/timg1_2.jpg',title: '合作商家(代收快递)',queryType: 'seller'},{id: 3,url: '../weicha/express/personal/index',imageUrl: '/images/weicha/timg1_3.jpg',title: '收件人(签收快递)'},{id: 4,url: '../weicha/express/logistics/index',imageUrl: '/images/weicha/timg1_4.jpg',title: '快递物流查询'}]})},onItemClick: function (e) {var targetUrl = e.currentTarget.dataset.payvar targetQueryType = e.currentTarget.dataset.indexif (targetQueryType == "seller") {var reqData = {seller_openId: app.globalData.openid,status: '2'}this.queryDBUtil("sellerInfo", reqData, targetQueryType, targetUrl,"亲,您暂未申请商家,请提交商家申请!")} else if (targetQueryType == "courier") {var reqData = {courier_openId: app.globalData.openid,status: '2'}this.queryDBUtil("courierInfo", reqData, targetQueryType, targetUrl,"亲,您暂未申请快递员,请提交快递员申请!")} else {wx.navigateTo({url: targetUrl})}},queryDBUtil: function (reqCollectionName, reqData,queryType, retUrl,retMgs){wx.cloud.callFunction({name: "utilsDB",data: {collectionName: reqCollectionName,collectionWhere: reqData},complete: res =>{let retStatus = '1'if (res.result.data.length >= 1) {retStatus = res.result.data[0].status}if (retStatus == '2') {if (queryType == "seller"){app.globalData.seller = res.result.data[0]} else if (queryType == "courier"){app.globalData.courier = res.result.data[0]}wx.navigateTo({url: retUrl})} else {wx.showToast({icon: 'none',title: retMgs})}},fail: err =>{wx.showToast({icon: 'none',title: retMgs})}})}})

我们在使用vue写项目的时候,会发现如果我导入一个文件,直接使用目录导入,目录下面放一个index.js,那么会直接导入index.js这个文件,这个是什么原因呢?

其实这个是webpack的一个默认配置,即:

resolve.mainFiles : ["index"],   这个配置的默认是index.js, 如果你想导入其它默认的文件,可以自己配置,比如我想默认default.js,可以这样配置:

exports = {

entry:'main.js',

.......

resolve:{

    mainFiles:["index", "default"]   // 注意,这个index必须要有,否则会报错

}

}