我想要一个文件.它的路径在某些配置中:
//config.js
module.exports = "/home/css/style.css";
//entry.js
var path = require(./config.js);
require("style!css!" + path);
Uncaught Error: Cannot find module "."
Run Code Online (Sandbox Code Playgroud)
如何要求包含可以获取根/目录的路径的文件?
你必须使用require.ensure
例如:
function handleRouteChange(path) {
require(['/views/' + path], function(PageView) {
app.setView(new PageView());
});
}
Run Code Online (Sandbox Code Playgroud)
更改为:
function loadPage(PageView) {
app.setView(new PageView());
}
function handleRouteChange(path) {
switch (path) {
case 'settings':
require(['/views/settings'], loadPage);
break;
case 'transfer':
require(['/views/transfer'], loadPage);
break;
case 'wallet':
require(['/views/wallet'], loadPage);
break;
default:
// you could either require everything here as a last resort or just leave it...
}
}
Run Code Online (Sandbox Code Playgroud)
来源:https://gist.github.com/xjamundx/b1c800e9282e16a6a18e#the-routing-code-old-and-new
| 归档时间: |
|
| 查看次数: |
800 次 |
| 最近记录: |