[英]Cross-device local assets location in Weex
Working with Weex 0.16 I generated the default "WeexDemo" project for Web, iOS and Android, and the default index files works without issue. 使用Weex 0.16,我为Web,iOS和Android生成了默认的“ WeexDemo”项目,并且默认的索引文件可以正常工作。
I'm trying to figure out the folder location where I can put image files and other assets. 我正在尝试找出可以放置图像文件和其他资产的文件夹位置。 I changed the "logoUrl" from an http url to a relative path ('bg.png')
我将“ logoUrl”从http网址更改为相对路径('bg.png')
Is there any solution where I can use the same folder to drop the assets and have it accessible for all devices? 有什么解决方案可以使我使用同一文件夹删除资产并使所有设备均可访问它?
Do as follows : 进行如下操作:
In your application class : 在您的应用程序类中:
WXSDKEngine.registerComponent("yourImage", YourImage.class);
create class YourImage.java and it should look like this : 创建类YourImage.java,它应如下所示:
public class YourImage extends WXComponent<ImageView> {
public YourImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
super(instance, dom, parent);
}
@Override
protected ImageView initComponentHostView(@NonNull Context context) {
ImageView imageView = new ImageView(context);
return imageView;
}
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
if (src == null) {
return;
}
if(null != getHostView()) {
Picasso.with(WXEnvironment.getApplication()).load(src).into(getHostView());
}
}
}
In your vue/js file 在您的vue / js文件中
<yourImage class="image" :src="url"> </yourImage>
In your WeexUIFragment/Activity : while loading page data through map, add one key and value as follows: 在您的WeexUIFragment / Activity中:通过地图加载页面数据时,添加一个键和值,如下所示:
HashMap<String, Object> map = new HashMap<>();
map.add("image_url", "android local asset url")
map.put("PAGENAME", "");
mWXSDKInstance = new WXSDKInstance(YourCurrentActivity.this);
mWXSDKInstance.registerRenderListener(YourCurrentActivity.this);
mWXSDKInstance.render(pageName, weexJSUrl, map, null, WXRenderStrategy.APPEND_ASYNC);
In JS file in script/data block to retrieve asset local image url: 在脚本/数据块中的JS文件中,以检索资产本地图片网址:
const url = _.get(weex,'config.image_url')
If you need more help: You can look into Component Extend section in below link : https://weex.incubator.apache.org/guide/extend-android.html 如果您需要更多帮助:您可以查看以下链接中的“组件扩展”部分: https : //weex.incubator.apache.org/guide/extend-android.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.