Guide on converting the <br> tag within a string to an HTML tag in VUE.js

When working with Vue.js, I often use {{}} to display my data on the HTML page. However, I recently encountered a situation where my data includes a string with
tags that I would like to be rendered as actual HTML tags when displayed.

data(){
  return {
    bodyText: 'aaaaaa<br>aaaaaa'
}
}
<p>{{bodyText}}</p>

My desired output within a span tag would look like this:

aaaaaa
aaaaaa

But instead, the actual result is: aaaaaa<br>aaaaaa

Answer №1

I believe the solution can be found by utilizing this resource:

<p>By using the v-html directive: <span v-html="rawHtml"></span></p>

Answer №2

Implement the v-html directive in your code:

<div><span v-html="content"></span></div>

Answer №3

Simplify it further by placing the v-html attribute directly inside the p tag

<p v-html="content"></p>

Answer №4

This is a sample of some html code:

<p>
    <strong>Hello World!</strong>
</p>

Here is the corresponding JavaScript function:

displayText: function () {
   return "This is just a test<br />To see how it works"
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remove bulleted list from HTML using JavaScript DOM

My task involved deleting the entire "agent" array using the removeChild() function, requiring the id of a <ul> element. However, I faced an issue as I couldn't set the id for the "ul" due to using the createElement() function. //old code < ...

Utilizing cookies to track the read status of articles - markers for reference

Currently, I am in the process of developing a website and am interested in implementing a feature that allows users to track which articles they have read. I am considering adding a small circle next to each article heading to signify whether it has been ...

What methods can I use to conduct tests on functions in a Vuex module?

I am exploring a Vuex module named user. After successfully registering my module in Vuex, it is functioning as expected. // store/index.js import Vue from 'vue' import Vuex from 'vuex' import user from './modules/user' Vu ...

I've been struggling with my Create React app for the past two days, and it just won

When trying to create a React project using the command `npx create-react-app reactproject`, I encountered an error: npm ERR! code ENOENT npm ERR! syscall spawn C:\Users\SUJITKUMAR\Desktop npm ERR! path D:\WebDev\React npm ERR! ...

Error: Attempting to subscribe to a post request returned a null result

Every time I attempt to subscribe to a post request, the TypeError: result is null is returned My setup involves an Angular CLI connecting with a Spring Boot application for a simple login page. My goal is to save the response header in local storage. Be ...

Create a rectangle when the mouse is pressed down

Creating a zoomable and pannable canvas in Fabric.js was easy, but now I am facing an issue with accurately drawing a rectangle on each mousedown event. The problem arises when the canvas is transformed from its original state, making the coordinates inacc ...

Oops! An error occurred: Uncaught promise rejection - invalid link found for ProductListComponent

I am currently in the process of learning Angular and Ionic, but I am feeling a bit confused as to where my mistake is. I have looked at other questions, but I still can't seem to figure it out. Can anyone provide some assistance? Perhaps someone has ...

Sending arrays in JSON format using Node.js Express (res.json)

I have a code snippet like this: app.get('/orders/:pizzeriaID/:status', async (req, res) => { try { const requestedOrderByPizzeriaID = req.params['pizzeriaID']; const requestedOrderByStatus = req.params['status']; ...

Having trouble with incorporating a feature for uploading multiple images to the server

At the moment, I have a code snippet that allows me to upload one image at a time to the server. However, I am looking to enhance this functionality to be able to upload multiple images simultaneously. I am open to sending multiple requests to the server i ...

Is there a way for me to loop through the URLs stored in an array and showcase them individually in an iframe?

This code snippet aims to iterate through a list of URLs and display the latest one in an iframe. It also incorporates jQuery's countdown plugin for additional functionality. <?php $count=0; $urls[]="http://www.techcrunch.com"; $urls[]="http://www ...

Utilizing reference memory to enable communication between two controllers

Within my Angular application, I have implemented a service to facilitate communication between 2 controllers and allow them to share the input variable from the search box. I am using kickSearch.box to reference memory...obj.property. However, there seem ...

Can security groups be dynamically updated using a JSON file in JavaScript rather than relying on manual parameters?

Looking to enhance security group rules, I aim to have my javascript file extract data from a separate json file instead of relying on json parameters directly. After initially using json parameters for security group updates, I am now exploring the metho ...

Exploring the utilization of props in single file components with Vue.js

Just starting out with vue.js, I'm utilizing single file components in conjunction with webpack. I am attempting to calculate the sum of {{operating.totaloperating}}. From what I've gathered, I need to pass the data back to the script as a prop, ...

Transferring information from blade to vue component in Vue/Laravel

Hey there, I'm currently diving into the world of Vue and trying to grasp its concepts. One thing that's been boggling my mind is how to tweak a component I've created for a create form so it can also be utilized for an edit form. Specifical ...

Utilizing JSON to transfer PHP array data for display using JQuery

Currently, I am working on a jQuery script that is responsible for fetching a PHP array from the MySQL database and converting it into a JSON object. The process is functioning correctly, as I can successfully output the raw JSON data along with the keys. ...

Is it possible to modify the inline onkeyup function?

Looking for a solution to change the onkeyup function in a textarea element from 255 characters to 150 characters without directly editing the code? <textarea cols="50" rows="4" id="textbox" onkeyup="limitArea(this, 255, '')"></textarea ...

Return to the previous URL after executing window.open in the callback

I need help redirecting the callback URL back to the parent window that initially called window.open. Right now, the callback URL opens inside the child window created by the parent. Here's the scenario: The Parent Window opens a child window for aut ...

Utilize the identical function value within a Vue template

In my template, I am encountering a recurring situation where I need to retrieve a value from a function. This function takes parameters from the template (such as the index of a v-for loop) and returns a result that is then displayed on the template. The ...

Generate a JSON structure from HTML with the help of jQuery

Issue Overview Imagine a scenario where there is a delivery of assorted candies. The delivery consists of multiple boxes, each containing various types of unique candies. Each box and candy type has its own distinct identifier. Moreover, every candy comes ...

The anticipated reply was supposed to consist of an array, however it ended up being an

I'm brand new to Angular and I've been searching for a solution to my issue with no luck. My app is supposed to retrieve data from a MongoDB database and display it to the user. However, I keep getting this error message: Error: [$resource:bad ...