在YML中使用HTML会产生[对象对象]
YML
context:
fieldLabel: |
<strong>
Some Bold Text
</strong> and now normal continued.
呈现为
context:
fieldLabel: ",[object Object], and now normal continued.↵"
但我希望输出应该是
context: { fieldLabel: '<strong>\n Some Bold Text\n</strong> and now normal continued.\n' },
我的JS代码:
我的JS代码:
const tests = YAML.safeLoad(this.props.children,{json:true});
console.log("tests",...tests)
控制台输出:
context:
fieldLabel: ",[object Object], and now normal continued.↵"
它作为[object Object]而不是<strong>\n Some Bold Text\n</strong>
答案 0 :(得分:0)
safeLoad(字符串[,选项])
推荐的加载方式。将字符串解析为单个YAML文档。返回一个JavaScript对象或在错误时引发YAMLException。默认情况下,不支持正则表达式,函数和未定义。此方法对于不受信任的数据是安全的。
当您在Yaml中包含非安全代码(即HTML)时,js-yaml似乎给了您一个错误。如果可以确保您的Yaml是安全的,则可以使用load()
进行非安全加载,或者可以修改代码的结构以更改yaml中存储的内容和不保存的内容。