You can use following way:
const checkFileExist = (path) => {
try {
return require(`${path}`);
} catch (err) {
return null;
}
};
and use it on your component
if(checkFileExist('../public/service/filename.json') === null) {
// something
} else {
// something
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…