问答

react-native加载静态图片或html , 显示文件找不到

作者:admin 2021-04-22 我要评论

测试手机为android ` //webview用的是react-native-webviewimport React, { Component, } from 'react';import { View, Text, Platform, Image, } from 'react-n...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

测试手机为android

`

//webview用的是react-native-webview


import React, { Component, } from 'react';
import { View, Text, Platform, Image, } from 'react-native'
import { WebView } from 'react-native-webview';
export default class Antv extends Component {
    constructor(props) {
    super(props);
    this.state = {
  
    }
}
render() {
return (
  <View style={{height: 300}}>
    <WebView
        ref={ref => (this.webViewRef = ref)}
        // onMessage={this.onMessage}
        originWhitelist={['*']}
        // allowFileAccess={true}
        // source={{uri:    'file:///android_asset/china_gdp.html'}}
        source={{uri: 'file:///android_asset/base/gdp.html'}}
        javaScriptEnabled={true}
        // decelerationRate='normal'
        scrollEnabled={true}
        // useWebKit={true}
        // mediaPlaybackRequiresUserAction={true}
        // mixedContentMode="compatibility"
        // allowingReadAccessToURL="*"
        // domStorageEnabled={true}
        // onLoadEnd={() => this.setState({ loading: false })}
    />
    <Image
        style={{width: 100, height: 100}}
        source={{uri: 'file:///android_asset/base/CustomerAnalysis.png'}}
    />
  </View>
)
}
}

`
android/app/src/main/assets
image

这样写完以后,运行,手机显示如下
image
webview显示没找到文件,Image也没有显示
这是哪里的问题呢?

###

file 后面要接绝对路径,你代码中的地址是相对于项目根目录的path

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • react-native加载静态图片或html , 显

    react-native加载静态图片或html , 显

  • linux 脚本问题求教

    linux 脚本问题求教

  • vue3.0在使用keep-alive组件时报内部错

    vue3.0在使用keep-alive组件时报内部错

  • 关于promise化的一些疑问,哪位老哥可

    关于promise化的一些疑问,哪位老哥可

腾讯云代理商
海外云服务器