问题描述
我希望在 React 中使用这个“https://www.npmjs.com/package/@vitalets/google-translate-api”库,但说明说我需要“const translate = require('@vitalets /google-translate-api');"。这在 React 中不起作用。
如果我尝试从“@vitalets/google-translate-api/index”导入{translate};我得到“关键依赖:需要函数的使用方式不能静态地依赖 提取"
如何在 React 中使用这样的库?
解决方法
Google translate API 用于 node.js,意思是你的后端
您可能正在寻找 Google Translate Open API 或 Translate Google Api 吗?但是第一个包好像坏了,而且好像都不经常使用/下载
下载时,请确保它可以在前端与 ReactJS/js 一起使用