Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image 组件在选择图片的时候会报 404 错误 #2601

Closed
neewbee opened this issue Mar 27, 2019 · 3 comments
Closed

Image 组件在选择图片的时候会报 404 错误 #2601

neewbee opened this issue Mar 27, 2019 · 3 comments

Comments

@neewbee
Copy link

neewbee commented Mar 27, 2019

Feature Request 请提到 FeatHub
问题描述
[问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]

业务代码中,请求接口获取图片地址,image组件拿到图片地址,渲染图片。
如果

  • 1: image 组件是条件渲染
  • 2: 拿到图片地址的时候小程序在后台(用户在选择图片界面)
    这时候从选择图片界面切回小程序, image 组件会报 404。尽管这个图片是可以访问的。

复现步骤

  • taro init
  • 关闭微信开发者工具的校验域名选项
  • 在pages -> index->index.js 中粘贴以下代码
  • 点击 chooseImage 按钮,等待3秒,退出选择照片界面
  • 可看到 image 组件空白
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Button } from '@tarojs/components'
import './index.less'

export default class Index extends Component {
  constructor() {
    super(...arguments)
    this.state = {
      show: false,
      url: ''
    }
  }

  config = {
    navigationBarTitleText: '首页'
  }
  onImageLoad(e) {
    console.log('imageload')
    console.log(e)
  }

  onImageError(e) {
    console.log('imageError')
    console.log(e)
  }

  chooseImage() {
    Taro.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success() {}
    })
  }

  componentDidMount () {
    setTimeout(() => {
      this.setState({
        show: true,
        url: 'https://via.placeholder.com/150'
      })
    }, 3000)
  }

  render () {
    return (
      <View className='index'>
        <Text>Hello world!</Text>
        {this.state.show ? (
          <View>
            <Image
              onLoad={this.onImageLoad}
              onError={this.onImageError}
              src={this.state.url}
            />
          </View>
        ) : ' '}
        <Button onClick={this.chooseImage}>chooseImage</Button>
      </View>
    )
  }
}

期望行为
[这里请用简洁清晰的语言描述你期望的行为]
image 组件正常渲染
报错信息

[这里请贴上你的完整报错截图或文字]

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

Taro v1.2.20


 Taro CLI 1.2.20 environment info:
   System:
     OS: macOS 10.14.3
     Shell: 5.3 - /bin/zsh
   Binaries:
     Node: 8.15.1 - ~/.nvm/versions/node/v8.15.1/bin/node
     npm: 6.4.1 - ~/.nvm/versions/node/v8.15.1/bin/npm
   npmPackages:
     @tarojs/components: 1.2.20 => 1.2.20
     @tarojs/plugin-babel: 1.2.20 => 1.2.20
     @tarojs/plugin-csso: 1.2.20 => 1.2.20
     @tarojs/plugin-less: 1.2.20 => 1.2.20
     @tarojs/plugin-uglifyjs: 1.2.20 => 1.2.20
     @tarojs/router: 1.2.20 => 1.2.20
     @tarojs/taro: 1.2.20 => 1.2.20
     @tarojs/taro-alipay: 1.2.20 => 1.2.20
     @tarojs/taro-h5: 1.2.20 => 1.2.20
     @tarojs/taro-swan: 1.2.20 => 1.2.20
     @tarojs/taro-tt: 1.2.20 => 1.2.20
     @tarojs/taro-weapp: 1.2.20 => 1.2.20
     eslint-config-taro: 1.2.20 => 1.2.20
     eslint-plugin-taro: 1.2.20 => 1.2.20
     nervjs: ^1.3.9 => 1.3.13

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]
小程序本身貌似是没有这个问题的

@taro-bot
Copy link

taro-bot bot commented Mar 27, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@jinjinjin0731
Copy link
Contributor

没有复现该问题

@taro-bot
Copy link

taro-bot bot commented Mar 27, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants