vue中使用v-html防止xss注入
一、下载 xss 依赖npm install xss --save二、main.js中引入xss包并挂载到vue原型上import xss from "xss";Vue.prototype.xss = xss;三、在vue.config.js中覆写html指令chainWebpack: config => {config.module.rule("vue").use("vue-loader"
·
一、下载 xss 依赖
npm install xss --save
二、main.js中引入xss包并挂载到vue原型上
import xss from "xss";
Vue.prototype.xss = xss;
三、在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;
});
}
更多推荐
所有评论(0)