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

Taro3, html解析图片mode默认使用scaleToFill,应该为widthFix #7374

Closed
hulin32 opened this issue Aug 19, 2020 · 6 comments
Closed
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@hulin32
Copy link

hulin32 commented Aug 19, 2020

相关平台

微信小程序

复现仓库

https://github.com/flyingalex/taro-v3-bug-demo/blob/master/src/pages/index/index.jsx
小程序基础库: 2.11.3
使用框架: React

复现步骤

https://github.com/flyingalex/taro-v3-bug-demo/blob/master/src/pages/index/index.jsx

期望结果

图片不被压缩

实际结果

图片被压缩

环境信息

👽 Taro v3.0.7


  Taro CLI 3.0.7 environment info:
    System:
      OS: macOS 10.14.4
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node
      Yarn: 1.16.0 - /usr/local/bin/yarn
      npm: 6.11.3 - ~/.nvm/versions/node/v10.17.0/bin/npm
    npmPackages:
      @tarojs/cli: ^3.0.7 => 3.0.7 
      @tarojs/components: 3.0.7 => 3.0.7 
      @tarojs/mini-runner: ^3.0.7 => 3.0.7 
      @tarojs/react: 3.0.7 => 3.0.7 
      @tarojs/router: 3.0.7 => 3.0.7 
      @tarojs/runtime: 3.0.7 => 3.0.7 
      @tarojs/taro: 3.0.7 => 3.0.7 
      @tarojs/webpack-runner: 3.0.7 => 3.0.7 
      babel-preset-taro: ^3.0.7 => 3.0.7 
      eslint-config-taro: 3.0.7 => 3.0.7 
      react: ^16.13.1 => 16.13.1 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Aug 19, 2020
@hulin32 hulin32 changed the title html解析图片mode默认使用scaleToFill,应该为widthFix Taro3, html解析图片mode默认使用scaleToFill,应该为widthFix Aug 19, 2020
@iamxiyang
Copy link

   Taro.options.html.transformElement = (el) => {
      if (el.nodeName === 'image') {
        el.setAttribute('mode', 'widthFix')
      }
      return el
    };

我觉得你的问题可以通过Taro提供的这个方法进行解决。

@hulin32
Copy link
Author

hulin32 commented Aug 19, 2020

@iamxiyang 确实,厉害!

看看官方怎么说,感觉默认的widthFix会好些

@Chen-jj Chen-jj added this to the 3.0.10 milestone Sep 3, 2020
@Chen-jj Chen-jj modified the milestones: 3.0.10, 3.0.11 Sep 10, 2020
@ZakaryCode ZakaryCode modified the milestones: 3.0.11, 3.0.12 Sep 18, 2020
@ZakaryCode
Copy link
Contributor

默认为 scaleToFill 是为了和小程序保持一致,可以参考 小程序文档

@Chen-jj Chen-jj removed this from the 3.0.15 milestone Oct 13, 2020
@gingerJY
Copy link

transformElement

你好,请问这个方法要写在哪里?我用transformElement,报错找不到

@tourze
Copy link
Contributor

tourze commented Apr 16, 2021

   Taro.options.html.transformElement = (el) => {
      if (el.nodeName === 'image') {
        el.setAttribute('mode', 'widthFix')
      }
      return el
    };

我觉得你的问题可以通过Taro提供的这个方法进行解决。

这是啥写法?有文档说明吗?

@iamxiyang
Copy link

这是啥写法?有文档说明吗?

@tourze @gingerJY

这是Taro3针对HTML渲染提供的,具体用法可以看一下教程,教程地址 https://taro-docs.jd.com/taro/docs/html#%E9%AB%98%E7%BA%A7%E9%80%89%E9%A1%B9

欢迎添加我创建的Taro QQ交流群:587912117 一起交流

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

6 participants