javascript - Vuejs : V-HTML data binding of html data against eslint rule

标签 javascript html vue.js data-binding eslint

我正在使用以下方法绑定(bind)html并显示在我的页面中。它工作得很好,但是我从我的 eslint 收到警告说“v-html”指令可能导致 XSS 攻击。eslint(vue/no-v-html)

  <button
        id="foreignerBtn"
        class="tabButton"
        @click="foreignerClick"
        v-html="textContent2"
      ></button>

然后我按照以下方法更改它。但我无法呈现 html 标签。
 <button
            id="foreignerBtn"
            class="tabButton"
            @click="foreignerClick"
          >{{ textContent2 }}</button>

最佳答案

正如 Decade Moon 提到的,如果传递给 v-html 的内容是经过净化的 HTML,您可以禁用该规则。
https://eslint.vuejs.org/rules/no-v-html.html
通过将 html 包装在

<!-- eslint-disable vue/no-v-html -->
<button
        id="foreignerBtn"
        class="tabButton"
        @click="foreignerClick"
        v-html="textContent2"
      ></button>
<!--eslint-enable-->

关于javascript - Vuejs : V-HTML data binding of html data against eslint rule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60842158/

相关文章:

javascript - 浏览器作为 UDP (dgram) 客户端

javascript - jQuery Each() 函数不起作用

javascript - 动态添加复选框时,用于从组中选择一个复选框的 JQuery 脚本不起作用

javascript - 在输入字段上使用 vue 指令(v-model、@input)时,vue 中的数据列表出现意​​外行为?

vue.js - 如何在vueJs中绑定(bind)多个类

javascript - DOM 元素位于 $el 之外的 VueJS 组件

vue.js - Vue ChartKick - 条形图的不同颜色

javascript - 为什么我收到 "(node:7424) UnhandledPromiseRejectionWarning"已处理错误消息?

javascript - 如何正确扩展 React Bootstrap 组件?

JavaScript 面向对象 : Implementation of Logging