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

Exclusive to Safari: Codesandbox is experiencing difficulties retrieving data from the localhost server

Would you mind helping me out with this technical issue I'm facing? For the server/API, I am using this link. As for the mock website, it can be found at this URL. The problem is that, in my code, I'm using axios to fetch data from the locally h ...

Extension for Chrome that enhances YouTube video playback experience

I'm struggling to figure out why this isn't functioning. I've reviewed the Google extension dev docs and examined some sample code. Checked various Stack Overflow questions and answers, but haven't received any helpful feedback or res ...

Using jQuery Plugin for Date Operations

I am in search of a jQuery tool that can assist me with date manipulations, such as: 1) Adding a specific number of days to a date and obtaining a new Date. 2) Determining the week of the year for a given date. 3) Calculating the number of days between two ...

Having trouble retrieving the default selected value using the index in Angular Material's mat-button-toggle functionality

I'm encountering an issue with setting the default value for a toggle button group. The code is simple and the toggle buttons are correctly fetching values from the index, but I can't seem to get one of them to be default selected. I tried settin ...

The output type of a function given an input

Essentially, I have successfully rendered a return type for my combined reducers using the following code: const rootReducer = combineReducers({ notes: notesReducer, categories: categoriesReducer, flyout: flyoutReducer // more reducers }); export ...

The primary view seamlessly integrates with the page following the invocation of the partial view

Whenever the button is clicked, a different partial view is returned based on the selected value from the drop-down list. Controller: [HttpPost] public ActionResult Foo(SomeViewModel VM) { var model = VM; if (Request.IsAjaxRequest()) { ...

Maintain form activity post submission using jQuery's addClass and removeClass methods

There is a button on my website that, when clicked, reveals a form. The code I am using for this functionality is: $('#theform').addClass('hidden') $('#theform').removeClass('hidden'); <div id="theform" c ...

Looking for guidance on how to specify the angular direction in the ng-repeat

I am facing a challenge with the structure of my ng-repeat directive and I am having trouble navigating through it. Here is a representation of the data in array format JSON style {"data":[ ["sameer","1001", [ {"button_icon": ...

Incorporate a unique identifier for dynamic elements

Is there a way to give generated divs the same name so I can markup them easily? $.getJSON("data/reviews.json", function(data){ for(var i=0; i<data.length; i++) { var review = sym.createChildSymbol("Template", "content"); review.$("title").html ...

Updating the title of a page on CoreUI's CBreadcrumbRouter dynamically

I'm currently developing a project with VueJS and the CoreUI admin template. Is there a way I can change the title of the current page as shown on the CBreadcrumbRouter? The GitHub documentation mentions that the script typically displays meta.label ...

Implementing a language switch feature with Vue, Vuex, and Vue-i18n

Why doesn't the page update in a new language when the mutation is changed? In my main.js file, I have implemented vue-i18n with Vue: import Vue from 'vue' import VueRouter from 'vue-router' import VueResource from 'vue-reso ...

Transfer an Array of Objects containing images to a POST API using Angular

Looking to send an array of objects (including images) to a POST API using Angular and Express on the backend. Here's the array of objects I have: [{uid: "", image: File, description: "store", price: "800"} {uid: "f ...

Tips for defining header and parameters when using route.get in Node.js

Looking to add custom headers and parameters when using route.get in Node.js? I am trying to set a specific value for the header and pass parameter values in the API URL. router.get("/getdata", async (req, res) => { // Set custom header re ...

Is there a way to dynamically change the height in jQuery/JavaScript?

I am encountering an issue with my embed code where the height changes randomly after a few seconds, depending on certain parameters. Here is an example of the code I am using: $( <embed></embed>) .attr("src", "http://www.bbs.com") ...

Compile the sources of an npm dependency using Brunch

Recently, I've been facing an issue while trying to develop my web application using Brunch. The problem arises from a specific npm package called animated-vue, which consists of sources programmed in ES2016. After adding this package as a dependency ...

Looking for some guidance on grasping the concept of strict mode in React and determining what actions can be considered side effects

The other day, I came across a strange bug in React and here is a simplified version of it. let count = 0; export default function App() { const [countState, setCountState] = useState(count); const [countState2, setCountState2] = useState(count); con ...

Make the current tab the active tab with the help of AngularJS

I have a set of five tabs that are functioning correctly. However, when I refresh the page, the active tab reverts back to its default state instead of staying in its current active state. Can anyone help me identify where I may be making a mistake? Here ...

What are the steps to implement scoped styles in Vue using Sass?

When I try to apply scoped styles, the code stops working. It works fine without using the scoped attribute. <v-dialog persistent content-class="myclass"> <style lang="sass"> .myclass max-width:380px But once I add s ...

Can a string be transformed into HTTP POST parameters?

Below is a snippet of code where I've utilized the .serialize() method to convert all form inputs into a string, which is then sent to the server: $.ajax({ type: "post", url: wp_urls.ajax_url, data: { action: "submit_form", ...

Identify dead hyperlinks on a webpage with the help of selenium webdriver while steering clear of links that

I have been trying to identify broken links on a webpage by extracting all anchor tags. However, some of the links are dynamically generated through JavaScript. When I attempt to print out the list of all the links, I encounter a StaleElementReferenceExcep ...