<template>
<div>
<image :src="src" style="width:80px;height:80px;" @click="tap"></image>
</div>
</template>
<script>
export default {
data() {
return {
src: "xcassets:tab_icon_home"
}
},
methods: {
tap() {
this.src = "xcassets:tab_icon_home_pre"
}
}
}
</script>
自定义图片加载
- (id <WXImageOperationProtocol>)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)userInfo completed:(void (^)(UIImage *image, NSError *error, BOOL finished))completedBlock {
if ([url hasPrefix:@"//"]) {
url = [@"http:" stringByAppendingString:url];
}
if ([url hasPrefix:@"xcassets:"]) {
UIImage *image = [UIImage imageNamed:[url substringFromIndex:9]];
completedBlock(image, nil, YES);
return (id <WXImageOperationProtocol>) image;
}
NSURL *imgUrl = [NSURL URLWithString:url];
return (id <WXImageOperationProtocol>) [[[SDWebImageManager sharedManager] imageDownloader] downloadImageWithURL:imgUrl options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *_Nullable targetURL) {
} completed:^(UIImage *_Nullable image, NSData *_Nullable data, NSError *_Nullable error, BOOL finished) {
if (completedBlock) {
completedBlock(image, error, finished);
}
}];
}
点击图片后报错
2017-10-26 14:00:45.807053+0800 colavideo[4753:1906658] \^[[fg0,128,0; <Weex>[debug]WXJSCoreBridge.m:274, callUpdateAttrs...0, 20, {
src = "xcassets:tab_icon_home_pre";
} \^[[;
2017-10-26 14:00:45.815417+0800 colavideo[4753:1906629] -[UIImage cancel]: unrecognized selector sent to instance 0x1c40bb540
2017-10-26 14:00:45.815886+0800 colavideo[4753:1906629] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage cancel]: unrecognized selector sent to instance 0x1c40bb540'
*** First throw call stack:
(0x186e37d38 0x18634c528 0x186e451f8 0x186e3d6e4 0x186d230dc 0x104415918 0x104414134 0x104e4d49c 0x104e4d45c 0x104e5c110 0x104e509a4 0x104e5d104 0x104e64100 0x186a62fe0 0x186a62c30)
libc++abi.dylib: terminating with uncaught exception of type NSException
自己解决了:同时实现WXImgLoaderProtocol和WXImageOperationProtocol
WXImgLoaderDefaultImpl: