1、下载
npm install xss -s
2、在使用wangeditor地方引入
import xss from 'xss
3、找到editor实例
this.editor = new E(this.refs.editor)
4、找到html内容过滤
this.editor.customConfig.onchange = (html) => {
//可以自定义白名单
var options = {
whiteList: {
img: ["src", "title", "target"],
},
};
myxss = new xss.FilterXSS(options);
let filterHtml = myxss.process(html);
let filterHtml = filterXSS(html); // 此处进行 xss 攻击过滤
this.$emit("change", filterHtml ); // 将内容同步到父组件中
};