How come vhtml isn't displaying nested << correctly?

I am currently working on an app that utilizes dynamic binding, where <> is a way to fetch data from the API dynamically. However, I am facing an issue when trying to render it in vhtml as the parent element is not displaying at all. My goal is to have the output look like this: Name: <<Name>>. Any ideas on how I can achieve this? Examples of code are attached below.

const app = new Vue({
  el: '#app',
  data () {
    return {
      htmlText: '<p> Name : <<Name>> </p>'
    }
   }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<span v-html="htmlText"></span>
</div>

Answer №1

Building upon the responses from Link and Xlm regarding the discussion on Vue: How to escape and render HTML string?

An approach suggested is to utilize a regular expression to substitute < with &lt; and > with &gt;

Note: While this method may serve as a temporary fix, for a more robust solution, it is advisable to handle this transformation within the API.

In your specific scenario,

 const app = new Vue({
   el: "#app",
   data() {
      return {
        htmlText: "<p> Name : <<Name>> </p>",
      };
   },
   methods: {
      htmlToText(html) {
          return html.replace(/<</g, "&lt;&lt;").replace(/>>/g, "&gt;&gt;");
      },
   },
});
<div id="app">
  <span v-html="htmlToText(htmlText)"></span>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

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

Substitute terms in a sentence while excluding those that are within a markdown hyperlink

I have created a function that substitutes any instances of words in an array with markdown links that lead to a glossary page. For example: const text = "This is an example text with an [example](example.com) markdown link."; const highlighted ...

Tips for swapping a component with another component in React.js without the need for a page refresh

class Navigation extends Component { constructor(props) { super(props); this.state = { width: window.innerWidth, } } updateWidth = () => { if (this.state.width > 700) { this.setStat ...

jQuery: A variety of ways to close a div tag

I am encountering some difficulties trying to make this work properly, any assistance would be highly appreciated. The goal is to have the div close when the user clicks the X button, as well as when they click outside of the wrapper container. Unfortuna ...

Uncaught data emitted by Express route not received by socket.io client

I have encountered an issue where the data emitted from a socket in my ExpressJS route file is not being read by the client-side JavaScript. server.js var express = require('express'); var path = require('path'); var app = express(); ...

Exploring the possibilities: Establishing a Connection between Node.js and MySQL

I encountered an issue while attempting to connect node.js to MySQL. Despite having installed MySQL and the necessary libraries, I am unable to establish a connection. How can I troubleshoot this error? Additionally, what is the best approach for retrievin ...

How can data be sent to the server in JavaScript/AJAX without including headers?

JavaScript - Is it possible to transfer data to the server backend without using headers? ...

Learn how to effectively utilize templateURL in an express and angular project

Our project utilizes Express without any view engine. To set up static directories, we have the following: app.use(express.static(__dirname + '/public')); app.use(express.static(__dirname + '/view')); app.use(express.static(__dirname + ...

Executing JavaScript code in the Selenium IDE

I'm having trouble figuring out how to execute JavaScript within the Selenium IDE. The objective is to enter text into an input field, with a backend setup that verifies the current time in the input field for testing purposes: Here's the input f ...

encountering a problem with permissions while attempting to update npm

Has anyone encountered a permission error with npm when trying to update to the latest version? I recently tried updating npm and received this error message. I'm unsure of how to resolve it. Any suggestions? marshalls-MacBook-Air:Desktop marshall$ n ...

Unveiling Vue3: A Guide to Retrieving the Entire Component State, Along with its Properties, in the Vue Error Handler - Tips on Transforming a Vue Component Instance into

Incorporating Vue3 with the composition API and Bugsnag for error management has been a game-changer. When an error arises, my goal is to send the entire component state where the error occurred to Bugsnag (specifically, the object returned from setup()). ...

To iterate through a multi-dimensional array

I am facing an issue with fetching data within an array in the code below var str = "Service1|USER_ID, Service1|PASSWORD" var str_array = str.split(','); console.log(str_array) for(var i = 0; i < str_array.length; i++) { str_array[i] = st ...

JQuery does not allow for changing the selection of a RadioButtonFor

I am currently working on a code that determines whether or not to display contact information. To achieve this, I am using the RadioButtonFor html-helper with a boolean value for the MVC view model in Razor. Upon loading the page, I need to switch from t ...

Angular ngx-translate not displaying image

My Angular application is utilizing ngx-translate to support multiple languages. I am trying to dynamically change an image based on the language selected by the user. However, I am facing difficulty in updating the image when a language is clicked. The ap ...

Acquiring JSON data nested within another JSON object in D3

After looking at this reference, I am attempting to integrate similar JSON data into my webpage. The challenge I am facing is that my JSON contains nested JSON. Here is an example of how my JSON structure looks: { "nodes": [ {"fixed":true,"classes": null, ...

Unable to retrieve AJAX response

I've been working on a page where I'm using AJAX to fetch data based on the selection of radio buttons. The three options available are 'Unapproved', 'Approved' and 'All'. My goal is to display the corresponding user ...

Using JavaScript to control the state of a button: enable or

In the process of creating a basic HTML application to collect customer information and store it in a database, I have encountered a specific user interface challenge. Once the user logs into their profile, they should see three buttons. Button 1 = Print ...

How can you retrieve the current user in express.js when incorporating socket.io?

I have a web app using the express framework and socket.io for real-time chat. I am trying to get the current user's username and create a room with them in it, but I am struggling to retrieve the user info when socket.on('connection') is ca ...

The behavior of Mozilla in handling JQuery attr() function may result in variations in design elements such as font-family or font-size

I'm currently working on the login form. Below is my view in CodeIgnitor: <div id="login-form"> <?php echo heading('Login', 2); echo form_open('login/login_user'); echo form_input('email', set_value ...

Error: The property 'scrollIntoView' cannot be read because it is null

class MessageApp extends Component { constructor(props) { super(props) this.state = { text: "", messages: [] } } componentDidMount() { const config = { apiKey: "<api-key>", authDomain: "<projec ...

There was an error code -32700 encountered while attempting to post form data to the jsonrpc endpoint

As I work on creating a billing form to send data to a jsonrpc endpoint, I encounter an issue. Despite receiving a status code of 200 from the server, the response I get is: {message: "Parse error. Invalid JSON was received by the server.", code: -32700,.. ...