vue中使用v-html防止xss注入
1.下载依赖npm install xss --save1.main.js中引入xss包并挂载到vue原型上import xss from 'xss';Vue.prototype.xss = xss2.在vue.config.js中覆写html指令chainWebpack: config => {config.module.rule("vue").use("vue-loader").load
·
1.下载依赖
npm install xss --save
1.main.js中引入xss包并挂载到vue原型上
import xss from 'xss';
Vue.prototype.xss = xss
2.在vue.config.js中覆写html指令
chainWebpack: config => {
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap(options => {
options.compilerOptions.directives = {
html(node, directiveMeta) {
(node.props || (node.props = [])).push({
name: "innerHTML",
value: `xss(_s(${directiveMeta.value}))`
});
}
};
return options;
});
}
更多推荐
已为社区贡献71条内容
所有评论(0)