[TOC]
Weex和Vue 的全局定义方法有所区别。
Vue 中在main.js中运用compuntes来定义全局。
Weex 中需要导出函数,函数中进行比较和判断,用来定义去全局方法,然后返回。如果定义多个全局,则用多个函数进行定义。
代码示例:
export function getUrl(bundleUrl,fileName,dir,host){
var nativeBase;
var isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0;
var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('WeexDemo.app') > 0;
if (isAndroidAssets) {
nativeBase = 'file://assets/';
}
else if (isiOSAssets) {
nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);
}
else {
host = host||'localhost:8081';
var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);
if (matches && matches.length >= 2) {
host = matches[1];
}
nativeBase = 'http://' + host + '/' + dir + '/';
}
var h5Base = './index.html?page=./' + dir + '/';
// in Native
var base = nativeBase;
if (typeof window === 'object') {
base = h5Base;
}
return base+fileName;
}
多个方法的需求,代码示例:
export function 方法名1(参数){
}
export function 方法名2(参数){
}
export function 方法名3(参数){
}
使用方法,在