Guide on using @input and contentEditable in Vue.js JSX syntax to transform a regular DOM element into an editable one

I came across a codepen showcasing how @input can be combined with contentEditable to create a custom input DOM without using an actual input element. However, I encountered issues trying to incorporate @input with JSX in VueJS. Is it not feasible to do so in JSX?

Below is the demo showing @input functionality without JSX implementation: https://codepen.io/supraniti/pen/Lypobx?editors=0010

Thank you.

JS

Vue.component('editable',{
  template:'<div contenteditable="true" @input="update"></div>',
  props:['content'],
  mounted:function(){
    this.$el.innerText = this.content;
  },
  methods:{
    update:function(event){
      this.$emit('update',event.target.innerText);
    }
  }
})

var example = new Vue({
  el: '#example',
  data: {
    text:"This text is editable!"
  }
});

HTML

<div id="example">
  <editable :content="text" @update="text = $event"></editable>
  <div>
    <pre>{{$data |json }}</pre>
  </div>
</div>

Answer №1

Oh, never mind. I just discovered that in JSX, you can use the onInput event on a regular span element!

Hopefully this tip helps someone save time!

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

What is the process of dynamically creating a Javascript object?

I have been experimenting with creating the following custom array: var deal_info = { "1": { "deal": { "deal_id": "1", "qty": "1", "option_price_sale": "7900", "price_ship": "2500", " ...

Apply the "ng-class" attribute to the parent of the chosen element

Another question arises in relation to the usage of ng-class... How can we dynamically add a class to the <ul> element when a <button> within its <li> is clicked? Check out the demo here Here is the HTML code snippet: <div ng-app=" ...

What purpose does the additional symbol "$()" serve in the selector "$($())"?

Currently, I am looking to incorporate a jQuery scrollspy feature into one of my ongoing projects. Upon coming across this jsfiddle (https://jsfiddle.net/mekwall/up4nu/), I successfully integrated it into my project. However, I have hit a roadblock while ...

Determine the active state of the router link to correspond with the prop

I am currently tackling a Vue project that involves vue-router with deeply nested routes, such as 2/company/staff/1/timeline. However, I have encountered an issue at the (...) /staff/:id section where all route links are appearing as active regardless of ...

Is there a way to retrieve all values in the pathname from a URL after the initial slash

Extracting pathname pathname: "/kids/dlya-malyshey/platya-i-yubki" By using the substr function, I will remove the initial slash location.pathname.substr(1,); Now, the result is kids/dlya-malyshey/platya-i-yubki The challenge is to extract all ...

Creating a custom AngularJS filter to search within an array of objects

I'm currently working with an object in my project: {"A":[],"B":[],"C":[],"D":[],"E":[],"F":[{"name":"Fargo","id":29}],"G":[],"H":[],"I":[],"J":[],"K":[],"L":[],"M":[],"N":[],"O":[],"P":[],"Q":[],"R":[],"S":[{"name":"Sullivan","id":23},{"name":"Sven" ...

Seeking assistance with iterating through a specific JSON data structure

I am dealing with JSON data that has a specific format: {"errors":{"toDate":["Date error_message"],"name":["name error_message"]}} OR {"success":{"toDate":["Date update_data"],"name":["name update_data"]}} I am looking for a way to loop through this d ...

SSE and the power of NodeJS through Express

Having trouble receiving SSE events in the browser. This is the server-side code (using Express): app.all('/callme', function(req, res){ res.writeHead(200, { 'Connection': 'keep-alive', 'Content-Type&apo ...

Update the 'duplicate' buttons according to the position in the array

My app features 14 buttons, each generating a replica button with the same text when clicked. The pre-existing buttons are numbered to aid in iteration. I'm currently attempting to organize the newly created replica buttons in ascending order from lef ...

Iterating through a JavaScript object and displaying the outcomes within the identical element

$(document).on('mouseenter', '.grid-img-hover', function() { var container = $(this); var jobId = container.parent().find('.title-wrap-hidden').text(); $.ajax({ url: 'db_client_job_name_lookup.php' ...

Instructions on toggling button visibility based on dropdown selection?

My goal is to have a button hidden by default, and when I select an option from a dropdown list, the button should appear. Check out the code on JSFIDDLE $(function() { $('#cashbill').change(function() { $('#bill_icon').hide() ...

Problems with displaying PHP echo statements in Ajax requests

I am in the process of creating an ajax-php event calendar and have integrated ajax within the form to Add events: function PostData() { var xhr; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); ...

Techniques for transferring form data from JavaScript to Java

Currently in my application, I have a signup form and I am facing an issue with storing the data in the backend. Since I am not well-versed in the backend development, I am struggling with this task. I'm using Netbeans 7.0 as my IDE and MySQL 5.6 for ...

An issue has been discovered with the Search function as JavaScript's Array.filter() and .map() methods are not functioning properly, resulting in

Currently, I'm working on integrating a search feature into my Flask application that will display the cities entered by users and are present in the JSON API results of a weather API. I am following a tutorial and have used a code similar to this: h ...

Dealing with React Native text overflowing beyond the screen width when using FlexWrap

I'm currently working on implementing a component in react native that consists of a row containing and components, but I'm struggling to achieve the desired outcome. Here's my current code: <View style={{ flexDirection: ...

Displaying a Nuxt Vue component according to a specified parameter or type

As a newcomer to Nuxt and Vuejs, I have been scouring the web for a solution to my issue without any luck. The problem I am facing is with a page containing components <VTextField></VTextField> and <VSwitch></VSwitch>. Below is a s ...

Utilizing Ionic to import and parse an Excel file for data processing

I need assistance in uploading an Excel file and reading it using Ionic-Angular. I tried the following code, but it only seems to work for browsers and not for the Ionic app on Android. Can someone please help me with this issue? I am trying to read the E ...

Exploring the fundamentals of authentication with Express JS

Currently, I am encountering a challenge while attempting to implement basic authentication with Username and Password using Express JS. The problem lies in the fact that when I try to incorporate an if statement within an app.use() function, it does not s ...

Is it possible to use export default Enum in TypeScript?

I am facing an issue with exporting an enum object as default at the top level in my code. Here is what I tried: export default enum Hashes{ FOO = 'foo', BAR = 'bar', } However, this resulted in an error message: Module parse failed ...

Adjust the color of the background when hovering with the cursor

I am currently working on a project with a menu of buttons that dynamically changes based on the elements in a list. For instance, if my list contains ["A", "B", "C"], then I would have a menu with 3 buttons. Here is how I display the buttons using a java ...