there are two way to init cube in browser
- from html tag
<script
data-base="/assets"
data-main="/main.js"
src="/${resbase}/cube_loader.js"
type="text/javascript"/><script>in this example, cube inited with configs wirtting in the
script's attribute (in html5, we can access this attrbute which start withdata-by apinode.dataset) the hole config properties see belew.
- using client-side api
<script type="text/javascript" src="/${resbase}/cube_loader.js"></script>
<script type="text/javascript">
(function () {
Cube.init({
base: '/assets'
});
Cube.use('/main.js', function (Main) {
Main.run({
// TODO global config here
});
})
})();
</script>options object properties:
- base {String}
the assets base path(http path), without the ending /,
like: /assets
- remoteBase {Object}
the remote assets base, this config is an object, like:
{
// remoteName: 'remotePath',
datav: 'http://datav.component.aliyun.com'
}cube support remote online script base, with remoteName as namespace, like datav:/npm/dcharts/line.js
- timeout {Number}
script loading timeout, unit ms, default is 15000ms
- version {String}
the static resource version, likemain.js?v=123, used to update cdn cache
- charset
set the loading script charset, default is utf-8, can be
gb2312, gbk, etc. this property is working on the html script tag
cube.js will inject Cube Object into window in browser env.
- Cube.init(options)
init cube
- Cube.use(script_abs_path, function(mod){})
- Cube.use([script1, script2, script3...], function (mod1, mod2, mod3){});