vue · Vue.js Basics
What is the difference between v-html and v-text?
Answers
- v-text sets the textContent of the node
- v-html sets the innerHTML of the element
- Both of the statements above are true.
- Both of the statements are false.
{{ message }}
var vm = new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!'
}
})
```
In the above example, the `{{ message }}` inside a text node will be replaced with the value of the `message` property from the Vue instance's data.
## Working with v-html
On the other hand, the v-html directive sets the `innerHTML` of the element, which interprets the HTML code in the provided string. This is useful if you need to output HTML code from your Vue instance's data.
For example:
```javascript