Vue 清理 href url

问题描述 投票:0回答:1

各位,我在 vue js 中遇到了类似

Make sure bypassing Vue built-in sanitization is safe here.
的问题,它是我从 API 中获取的 URL,然后我尝试使用
@braintree/sanitize-url
进行清理,然后将其放入我的
Vue.prototype.$sanitize
中,如下所示这个

import { sanitizeUrl } from "@braintree/sanitize-url"

Vue.prototype.$sanitize = sanitizeUrl

然后我像这样在我的组件上使用它

data: () => ({
  sanitizeUrl: null
}),
created() {
  // BEFORE SANITIZE : "https://codepen.io/"
  // AFTER SANITIZED : "https://codepen.io/"

  this.sanitizeUrl = this.$sanitize(this.obj.info.url)
}
<a
  :href="sanitizeUrl"
  target="_blank"
  rel="noreferrer noopener nofollow"
/>

一切都很好,但声纳云仍然检测到该 URL 尚未清理 喜欢

Make sure bypassing Vue built-in sanitization is safe here.

如何从我的 API 中清理此 URL?谢谢大家

javascript vue.js sonarqube
1个回答
0
投票

使用这个可以帮助我清除错误

:href =“sanitizeUrl?sanitizeUrl:''”

© www.soinside.com 2019 - 2024. All rights reserved.