WEB/Vue.js

[Vuejs] v-html

S0PH1A 2020. 12. 4. 11:41
๋ฐ˜์‘ํ˜•

v-html

 

 

๐Ÿ‘ v-html

vue์—์„œ html ๊ทธ๋Œ€๋กœ ์ ์šฉ์‹œํ‚ฌ ๊ฒฝ์šฐ, v-html ์˜ต์…˜์„ ์ด์šฉํ•ด์„œ ์ ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

ex) TextEditor(quill)์—์„œ ์ž…๋ ฅํ•œ ๋‚ด์šฉ์„ ํ‘œ์‹œํ•  ๋•Œ, ๊ฐ’์„ html ๋กœ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— html์„ ๊ทธ๋Œ€๋กœ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” v-html์„ ์ด์šฉํ•œ๋‹ค.

<template>
	<div v-html="contents" />
</template>

<script>
export default {
	data: () => ({
    	contents: '<span>aaaa</span>',
    }),
}
</script>
  • vue์—์„œ v-html์‚ฌ์šฉ ์‹œ  XSS ๊ณต๊ฒฉ ์˜ˆ๋ฐฉ์„ ์œ„ํ•ด eslint ์—์„œ ๊ฒฝ๊ณ (warning)๋ฅผ ๋ฐœ์ƒํ•œ๋‹ค.

  • ๊ฒฝ๊ณ ๋ฅผ ์—†์• ๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ฝ”๋“œ ์ตœ์ƒ๋‹จ์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
  • ์ฐธ๊ณ : https://github.com/vuejs/eslint-plugin-vue/issues/260
<!-- eslint-disable vue/no-v-html -->

 

 

 

๋ฐ˜์‘ํ˜•