写的数据库有点儿大,超过2M,所以想实现读取分包程序,测试一下了,把数据库分开可以读取,代码如下:
var module;
const articlesData = require('../data/data.js');
const articlesData = require('../data/data2.js');
但是如果把data2挪到分包里面,就会显示错误,代码如下:
var module;
const articlesData = require('../data/data.js');
const articlesData2 = require('../../fenbao/pages/data/data2.js');
错误显示如下:
VM18757:11 页面【pages/kj/kj]错误:
Error: module 'pages/fenbao/pages/data/data2.js' is not defined, require args is '../../pages/fenbao/pages/data/data2.js'
at C (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at n (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at kj.js:3
at C (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at <anonymous>:8:5
at evaluateRes (VM9 asdebug.js:1)
at VM9 asdebug.js:1
at Object.invoke (VM9 asdebug.js:1)
at r (VM9 asdebug.js:1)
at E (WASubContext.js?t=wechat&s=1693622315844&v=2.20.1:2)(env: Windows,mp,1.06.2307250; lib: 2.20.1)
WAServiceMainContext.js:2 Uncaught FrameworkError
module 'pages/fenbao/pages/data/data2.js' is not defined, require args is '../../pages/fenbao/pages/data/data2.js'
Error: module 'pages/fenbao/pages/data/data2.js' is not defined, require args is '../../pages/fenbao/pages/data/data2.js'
at C (http://127.0.0.1:59778/appservice/__dev__/wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1:5584)
at n (http://127.0.0.1:59778/appservice/__dev__/wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1:4741)
at weapp:///$pages/kj/kj.js:7:21
at C (http://127.0.0.1:59778/appservice/__dev__/wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1:5787)
at <anonymous>:8:5
at evaluateRes (http://127.0.0.1:59778/appservice/__dev__/asdebug.js:1:94152)
at http://127.0.0.1:59778/appservice/__dev__/asdebug.js:1:10877
at Object.invoke (http://127.0.0.1:59778/appservice/__dev__/asdebug.js:1:12363)
at r (http://127.0.0.1:59778/appservice/__dev__/asdebug.js:1:101392)
at E (http://127.0.0.1:59778/appservice/__dev__/WASubContext.js?t=wechat&s=1693622315844&v=2.20.1:2:2055226)(env: Windows,mp,1.06.2307250; lib: 2.20.1)
Error: module 'pages/fenbao/pages/data/data2.js' is not defined, require args is '../../pages/fenbao/pages/data/data2.js'
at C (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at n (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at kj.js:3
at C (wxmodule.patch.js?t=wechat&s=1693622315844&v=2.20.1:1)
at <anonymous>:8:5
at evaluateRes (VM9 asdebug.js:1)
at VM9 asdebug.js:1
at Object.invoke (VM9 asdebug.js:1)
at r (VM9 asdebug.js:1)
at E (WASubContext.js?t=wechat&s=1693622315844&v=2.20.1:2)(env: Windows,mp,1.06.2307250; lib: 2.20.1)
请教各位大神,是目前小程序限制没办法读取分包的数据,还是写的代码有问题?
不支持,可以看看分包异步化:https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/async.html
这个不支持。