[英]How do i choose import/export in React
I want to use WebP when the user open the Page in Chrome and else it should be png. 当用户在Chrome中打开Page时,我想使用WebP,否则应为png。
i found this Code: 我发现此代码:
var isChrome = !!window.chrome && !!window.chrome.webstore
But i cant put an If-statement around export or import 但是我不能在出口或进口周围写一个If语句
This is my Code so far: 到目前为止,这是我的代码:
import redditwebp from '../img/icons/reddit.webp';
import redditpng from '../img/icons/reddit.png';
var isChrome = !!window.chrome && !!window.chrome.webstore;
if(isChrome){
export default {redditwebp}
}
else{
export default {redditpng}
}
you shouldnt really be doing normal if statements you should do an inline one 如果您应该使用内联语句,则您实际上不应该正常运行
const isChrome = !!window.chrome && !!window.chrome.webstore;
then in your actual code inline 然后在您的实际代码中内联
<div>{isChome ? <img src={redditwebp} alt="" /> : <img src={redditpng} alt="" />}</div>
to me that is the best way to do it, you may have to write this.isChrome
im not sure whether you will or not. 对我来说,这是最好的方法,您可能必须编写this.isChrome
即时消息,不确定是否愿意。
i will make this clearer. 我会说得更清楚。
import redditwebp from '../img/icons/reddit.webp';
import redditpng from '../img/icons/reddit.png';
import React, { Component } from 'react';
const isChrome = !!window.chrome && !!window.chrome.webstore;
export default class logo extends Component {
render(){
return (
<div>{isChome ? <img src={redditwebp} alt="" /> : <img src={redditpng} alt="" />}</div>
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.