How do you update the bind value in VueJs when using :value="text"?

My attempts at updating a string when the content is changed inside a textarea are not successful.

Vue component:

<template>
  <div>
    <textarea :value="text" @change="changed = true" @keyup="changed = true"></textarea>
    <div class="buttons">
      <button @click.prevent="saveChanges">Save Changes</button>
      <button @click.prevent="discardChanges">Discard Changes</button>
    </div>
  </div>
</template>

<script>
export default {
  name: "Editor",
  props: ["fileText"],
  data() {
    return {
      changed: false,
      text: this.fileText,
      sendText: "",
    };
  },
  computed: {
    getCurrentText() {
      return this.text;
    }
  },
  methods: {
    emitToParent() {
      this.$parent.$emit("custom-event", this.changed);
    },
    saveChanges() {
      if (this.changed) {
        console.log("I changed");
        this.sendText = this.getCurrentText;
        this.changed = false;
        this.$emit("close");
        console.log(this.sendText);
      } else {
        this.$emit("close");
      }
    },
    discardChanges() {
      this.text = this.fileText;
      this.$emit("close");
    },
  },
};
</script>

Despite my efforts to modify text in the textarea, the Save Changes button does not reflect those changes and returns the unmodified text.

In essence, I aim to update the text within a file. The component mentioned above retrieves the fileText from its parent element and should relay back any modified text to the parent. This process ensures that the file's content is updated only when there are actual modifications.

This version is preliminary and subject to alterations.

Answer №1

VIEW DEMO

If you find yourself using :value="text", consider switching to v-model="text" instead.

Here is an example:

<textarea v-model="text" @change="changed = true" @keyup="changed = true"></textarea>

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

The tabbing feature in bxslider disrupts the alignment of slides, making it

After encountering accessibility issues, I upgraded the bxslider library to version 4.2.3 for better support. Check out this example of bxslider where you can easily tab through the controls: http://jsfiddle.net/qax7w8vt/2/embedded/result/ The problem a ...

What is the best way to add the current date to a database?

code: <?php session_start(); if(isset($_POST['enq'])) { extract($_POST); $query = mysqli_query($link, "SELECT * FROM enquires2 WHERE email = '".$email. "'"); if(mysqli_num_rows($query) > 0) { echo '<script&g ...

Accessing the Nuxt store in module mode from a JavaScript file

I'm facing a challenge with my Nuxt app, where I have an AuthService within a namespaced store. The issue lies in how to import the store into my AuthService so that I can commit mutations from there. In some examples I've seen, the store is imp ...

Error: Attempting to assign a value to a property that is not defined (specifically 'Authorization')

I've been having trouble with my axios not setting headers. I've searched high and low for a solution, but no luck so far. Everything seems fine, but when I try to paste the provided code into a created hook method, I end up with an error in the ...

Using jQuery to replace the value of a button with a variable string that has been concatenated

I am facing a dilemma with a button on my webpage. The value displayed on the button is a combination of variables and strings, like so: $('#btn1').attr('value','question'+currid+'ans1').button('refresh'); ...

Placing the IconButton within an AppBar Component using React-JS

Trying to position two IconButtons within a Toolbar, one on the right side and the other on the left side. However, both are ending up on the right side. Here's my code: <AppBar position="fixed" > <Toolbar> <Ic ...

Stop the recurrence of multiple clicks by incorporating a Bootstrap modal popup confirmation

$('button[name="remove_levels"]').on('click', function (e) { var $form = $(this).closest('form'); e.preventDefault(); $('#confirm').modal({ backdrop: 'static', ...

Leverage Vue Router with scripting

I've come across a script that automatically redirects users to the login screen if they receive response code 401 from an API, indicating that their session has expired. import axios from 'axios'; axios.interceptors.response.use(function ...

The 'import' statement is not functioning properly within a script in the rendered HTML

While working on an express application, I've encountered a recurring error that I can't seem to solve. The error message is: "GET http://localhost:3000/javascript/module2 net::ERR_ABORTED 404 (Not Found)" Could someone kindly assist me in ident ...

Using AJAX (jQuery) to process and refine JSON data through filtration

I need assistance with filtering a JSON array using AJAX but I'm unsure of how to proceed. { posts: [{ "image": "images/bbtv.jpg", "group": "a" }, { "image": "images/grow.jpg", "group": "b" }, { "image": "images/tabs.jpg", ...

Executing a function within a ng-repeat iteration

Is there a way to call a method within an ng-repeat loop, even if the element does not exist at that moment? I'm facing this issue and I'm not sure how to resolve it... The ID seems to be correct. Strangely, when I run it in the console after ev ...

What is the best location in my redux store to store my socket connection?

As a beginner in the world of Redux, I've been using slices and redux-thunks to manage my redux store. However, I've come to realize that storing my socket connection in the state is not ideal. This connection is critical across multiple componen ...

Displaying client-side filtered rows in a jqGrid with postData filter upon initial loading

Our website includes a jqGrid that initially retrieves its rows using the built-in ajax fetch feature, returning a json object. We then apply filtering and searching on the client side by creating custom functions to generate postData filters. However, we ...

The method for viewing stack traces in Express JS server logs

In my tech stack, I'm utilizing Nuxt (Vue), Express.js, and Axios. Encountering a scenario where a REST call fails, exemplified by the code snippet below: axios.get('api/data-test'); The client displays an error message like this: xhr.js ...

Executing the Javascript function specified above upon the page being loaded

I'm fairly new to JavaScript, so please bear with me. I've got a JavaScript function on my page: <script type="text/javascript"> Sys.debug = true; var popup; Sys.require(Sys.components.popup, function () { popup = Sys.c ...

Exploring the Magic of ES6 Object Destructuring

Learning about ES6 destructuring is still new to me. I have encountered a scenario where I need to extract specific values from a nested object within an object. For instance - z = {g: 1, h: 2, i: {d1:5, d2:6, d3:7}} When attempting to destructure with ...

Error message: Unforeseen node express token problem

Whenever I attempt to call the endpoint provided below, Postman returns an error as shown: { "success": false, "error": "Unexpected token / in JSON at position 7" } Within the addFollowing function, you'll notice that I ...

What is the best way to extract a CSS rule using PHP?

Below is an example of the stylesheet I am currently using: #thing { display: none; } I am looking to retrieve the value of the 'display' property using PHP instead of Javascript. While I know how to do this with Javascript, I would prefer to u ...

Implementing the 'not-allowed' cursor style on disabled rows in Material UI datagrid

I have a specific disabled row in a Material UI data grid where users are unable to select or perform any actions on it. I am looking to display the cursor as "not-allowed" on this particular row. How can we apply styling to only this row since there is no ...

The button's URL will vary depending on the condition

As a newcomer to coding, I am seeking guidance on creating a button with dynamic URLs based on user input. For instance, let's say the button is labeled "Book Now" and offers two package options: Standard and Premium. I envision that if a user selec ...