7

I am making a blog app using Vue.js for frontend and Node.js for backend.

I am using a rich text editor (vue2-editor) in frontend for users to create the content of the blog. I want to store that content in the database (MySQL) and retrieve it. Currently whatever content I am storing is going as a plain HTML.

<p><strong>This is Blog Heading</strong></p><p><br></p><p><u>This is underlined</u></p><p><br></p><p>This is start of the paragraph</p>

And after retrieving from the database it renders is as a string and not HTML

How can I get it to display the HTML properly?

2 Answers 2

12

Use v-html to display it as html and not a string.

You can read more about it here:

https://v2.vuejs.org/v2/guide/syntax.html

Example:

<div v-html="htmlFromDb" />
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks.. I tottaly forgot it..Btw can you tell me..is it okay to store the html in database? what i mean is "is it the right way of implementing"?
There is nothing dangerous about storing html inside a DB. However, the danger can come when you display it in the users browser. For example, if you store malicious javascript in your DB nothing will happen. But when it is loaded in users browsers it could do some harm. So maybe add some checks and make sure only people you trust/now what they are doing can store the html.
Ok Thanks.. and sorry to bother you one more time.. But I have one last question.. if the user adds to many images and text.. will it affect my database? I mean, in terms of size. and what should be the column's type in the database for storing such content. I have set the the column's type to TEXT in mysql.
You should not store images to your database instead store path. that way there will be no size issue. for long texts TEXT is a good choice.
1

Providing you a solution as per my knowledge hope it will help you. Please have a look on code.

<p><strong>This is Blog Heading</strong></p>
<p><br></p>
<p><u>This is underlined</u></p>
<p><br></p>
<p>This is start of the paragraph</p>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.