当前位置: 代码迷 >> 综合 >> vue中使用v-html防止xss注入
  详细解决方案

vue中使用v-html防止xss注入

热度:12   发布时间:2024-02-28 09:57:18.0

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;});
}
  相关解决方案