1

微信答题小程序开发遇到过的坑

 2 years ago
source link: https://blog.51cto.com/u_15335909/5111777
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

我在开发答题小程序、考研题库小程序过程中,遇到过的坑以及其解决办法,在此做个笔记。

小程序页面栈最多十层

问题:假设小程序内有20个问题页面,答完上一个问题后wx.navigateTo到下一个问题页面,那么到第十题时,你会发现wx.navigateTo跳转不到下一个页面。

分析:这是因为使用wx.navigateTo跳转会把当前页面保存到页面栈中,而小程序页面栈最多十层。

解决:使用wx.redirectTo或wx.reLaunch替代。

微信答题小程序开发遇到过的坑_绝对路径

require的路径不支持绝对路径

问题:在嵌套比较深的目录层级里,引用utils/request.js,需要慢慢../到根目录

// in page.js
const util = require('../../../../utils/util.js');

解决:在App绑定require,Page里获取app,直接app.require引入

// in app.js
App({
onLaunch() {

},
require(path) {
return require(`${path}`)
},
})

// in page.js
const app = getApp()
const util = app.require('./utils/util.js');

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK