Vue V Html

Posted on  by admin

Modified11 months ago. I come from a react background with JSX, so using something like . to set the html of some things is pretty common. I know you can achieve the same thing using v-html, but was wondering if it was the best/safest way to do so given my following code:. 2020 gold badges7474 silver badges141141 bronze badges. 141141 bronze badges. If you want to include the ability to have HTML rendered from a vue property, you're going to need to use v-html. If you're allowing users to modify the property that the HTML may come from, then you're going to run into security concerns with XSS vulnerabilities, in which case you'll need to sanitize your inputs when the data is sent back to the server (I highly encourage you to use a reputable external library for this).

If users won't be modifying your data, then there should be no safety concerns with using v-html at all.

Whenever you allow users to modify data of any kind, you open yourself up to potential security issues.

You'll just need to anticipate what those issues are and work around them. June 2021 Update. To clarify a point, if you don't need dynamic HTML rendering and only need to handle a conditional case for rendering certain predetermined HTML templates, then you can simply include conditional rendering in your Vue template.

An example may look like this:. In short, if you don't need dynamic HTML rendering and only need conditional HTML rendering, then use v-if where applicable and structure your data to allow for conditional rendering to function correctly.

Otherwise use v-html, or possibly even structure JSON data to recursively generate predefined components using (this is fairly complicated, so I will not be going into detail in this answer).

11 gold badge1818 silver badges3333 bronze badges.

3333 bronze badges. Vue JS is a front end framework getting all the traction it deserves. It is created by cherry-picking the best features of Angular and React, The Two popular Frontend Java Frameworks in the modern IT industry.

It is a wonderful and robust framework that you can count on.

I myself have used it for various purposes like Mobile App, WebSite Development, Desktop App with Electron etc. It is easy to use.