javascript - REACT-NATIVE - abcjs - ReferenceError:找不到变量:元素
问题描述
import abcjs from 'abcjs';
export default class MusicScore extends Component {
constructor(props) {
super(props);
this.state={
data: this.props.navigation.getParam('abctune'),
}
}
render(){
data = this.state.data;
renderScore = () => {
abcjs.renderAbc('notation', data);
}
return(
<WebView
source={
{html: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="notation"></div>
</body>
</html>
`}
}
domStorageEnabled
javaScriptEnabled
injectJavaScript={renderScore}
/>
);
}
}
上面的代码产生以下
开发环境:
操作系统:Windows 10
节点:v12.10.0
安卓工作室:3.5.2
通过包管理器安装:
npm install --save abcjs
解决方案
不幸的是,您需要设置 DOM。我没有使用 react-native,所以我不确定这是否可行:
使用 SSR 包(如 Nuxt)时,对我有用的是将导入更改为稍后的过程。所以:
mounted() {
const abcjs = require('abcjs');
}
react-native 中有类似的东西吗?
推荐阅读
- c# - DocuSign 文本框的值在查看时消失
- java - 处理回复 GenericMessage 时未找到连接
- android - 将所有四个都移动到 theme.XML 时不应用约束
- javascript - 删除vuetify中的项目后如何保留页面
- java - 处理动态字符串上的多个子字符串时出现问题
- javascript - Javascript Google Chart 中未填写 Chartdata 变量
- python - “最长递增子序列”问题的动态解的成本函数
- machine-learning - 神经网络只预测一类
- java - 即使使用 toString() 方法,尝试打印 ArrayList 也会返回随机符号
- kubernetes - 规模 1 的部署有 2 个 pod