Nuxt v-html
Chúng ta phải luôn vệ sinh các giá trị đầu vào của người dùng trên máy chủ. Chỉ vệ sinh với Vue trong những trường hợp cần thiết (e. g xem trước đánh dấu) Show
Cài đặt
hoặc là
Cách sử dụngĐăng ký plugin import Vue from 'vue'; import VSanitize from "v-sanitize"; Vue.use(VSanitize); Sử dụng với NuxtJS 1export default { modules: [ ['v-sanitize/nuxt', { /* options */ }] ], sanitize: { /* options */ } } Bạn cũng có thể vượt qua các tùy chọn mặc định defaultOptions = { allowedTags: ['a', 'b'], allowedAttributes: { 'a': [ 'href' ] } }; Vue.use(VSanitize, defaultOptions); Sử dụng nó trong các thành phần của bạn <template> <div contenteditable="true" @paste="sanitize">div> template> <script> export default { methods: { sanitize(event) { event.preventDefault(); const html = this.$sanitize(event.clipboardData.getData('text/html')); //or //const html = this.$sanitize( // event.clipboardData.getData('text/html'), // { // allowedTags: ['b', 'br'] // } //); document.execCommand('insertHTML', false, (html)); } }, } script> APIyarn add v-sanitize 2tùy chọn
Plugin này phụ thuộc vào sanitize-html. Chi tiết xem tại đây yarn add v-sanitize 4dơ bẩn
tùy chọn
Nếu bạn không vượt qua một tùy chọn, các tùy chọn mặc định sẽ được sử dụng
yarn add v-sanitize
|