What is the best way to transfer Tiptap-vuetify HTML source code between different components?

I've implemented the Tipap text editor in my Nuxt project. I'm facing an issue where when I update the data in another component (in pages/blogs/editor.vue) that was initially passed from a different component (in components/blogs/Editor.vue), the initial content does not get updated and keeps showing the same data.

Below is the code snippet:

in components/blogs/Editor.vue

<script>
// import the component and required extensions
import {
  TiptapVuetify,
  Heading,
  Bold,
  Italic,
  Strike,
  Underline,
  Code,
  Paragraph,
  BulletList,
  OrderedList,
  ListItem,
  Link,
  Blockquote,
  HardBreak,
  HorizontalRule,
  History
} from "tiptap-vuetify";
export default {
  // specify TiptapVuetify component in "components"
  components: { TiptapVuetify },
  data() {
    return {
      localHTML: "",
      localJSON: "",
      post_content:'',
      // declare extensions you want to use
      extensions: [
        History,
        Blockquote,
        Link,
        Underline,
        Strike,
        Italic,
        ListItem,
        BulletList,
        OrderedList,
        [
          Heading,
          {
            options: {
              levels: [1, 2, 3]
            }
          }
        ],
        Bold,
        Link,
        Code,
        HorizontalRule,
        Paragraph,
        HardBreak
      ],
      // starting editor's content
      content: `
      <h1>Yay Headlines!</h1>
      <p>All these fwer <strong>cool tags</strong> are working now.</p>
    `
    };
  },
  mounted() {
    this.$emit("content", this.content);
  }
};
</script>
<template>
  <div>
    <ClientOnly>
      <!-- Use the component in the right place of the template -->
      <tiptap-vuetify
        v-model="content"
        :extensions="extensions"
        :toolbar-attributes="{ color: 'black', dark: true }"
      />
      <div class="export">
        <h3>HTML</h3>
        <pre><code>{{ content }}</code></pre>
        <h2>post</h2>
        <!-- <p>{{post_content}}</p> -->
        <!-- <p>{{localHTML}}</p> -->
        <v-divider />
      </div>
      <template #placeholder>
        Loading...
      </template>
    </ClientOnly>
  </div>
</template>

in pages/blogs/editor.vue

<script>
import Editor from "../../components/blogs/Editor.vue";
import axios from "axios";
export default {
  data() {
    return {
      post_title: "",
      short_description: "",
      content_image_url: "",
      content: "",
      post_content: ""
    };
  },
  methods: {
    getContent(e) {
      this.content = e;
      this.post_content=content;
    },
    submitForm() {
      let data = {
        post_title: this.post_title,
        short_description: this.short_description,
        content_image_url: this.content_image_url,
        post_content:this.content
      };
      axios
        .post("http://localhost:8000/api/posts/add", data, {
          headers: {
            Accept: "application/json"
          }
        })
        .then(res => {
          console.log(res);
        })
        .catch(err => console.log(err));
    }
  },
  components: {
    Editor
  }
};
</script>
<template>
  <v-app>
    <v-container>
      <section>
        <h1 class="display-1">
          Tiptap Vuetify
        </h1>
        <Editor v-on:content="getContent($event)" />
        <h2>getContent</h2>
        <p>{{ content }}</p>
        <v-layout justify-center>
          <v-btn to="/blogs" outlined color="info">Back</v-btn>
          <v-divider />
          <v-btn color="info" form="post-form" type="submit">Publish</v-btn>
        </v-layout>
      </section>
    </v-container>
  </v-app>
</template>
https://i.sstatic.net/vzEjB.png

https://i.sstatic.net/MpgXP.png

Answer №1

I have discovered the solution. By referring to the Tiptap-vuetify documentation, you can find an event that allows you to handle keypresses using the keydown method.

This event is triggered when the editor receives a keydown event.

<tiptap-vuetify
  @keydown="onKeyDown"
/>
methods: {
  onkeydown (event, view) {
    console.log('event', event.key)
  }
}

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

"Uncovering a memory leakage issue within a recursive polling function in JavaScript

Current issue in need of resolution: My team and I are currently working on a large application that was initially released around two years ago. We are in the process of adding a new "always-on" status screen to the application, which will be the default ...

The logo image dynamically switches as the user scrolls through various colored sections

Looking to create a feature that changes the logo image as users scroll through different colored sections. Specifically, switching between dark and light themes. a) How can we determine if the section the user is currently on has a dark or light theme? b ...

Guide on navigating an array of objects using the provided keys as a starting point in Javascript/Typescript

Assuming I have an array of objects structured like this: const events: Array<{year: number, month: number, date: number}> = [ {year: 2020, month: 10, date: 13}, {year: 2021: month: 3, date: 12}, {year: 2021: month: 9, date: 6}, {year: 2021: mont ...

What is the process for incorporating a custom function into a resource controller in Laravel?

I'm in the process of developing a custom function for a Controller class that is serving as a ResourceController. The reason behind this is that I only need to update a single field, while I still want to maintain the existing update function for oth ...

Top method for individually choosing multiple selections from a foreach loop output

Need help with a loop: foreach ($userItems_get as $item => $value) { if ($value['prefab'] == 'wearable') { echo $value['name'] . "</br>"; echo "<img src=\"{$value['image_invent ...

Attempting to trigger the onchange function established by jQuery

Within my code, I have a change listener set on the checkboxes in this section: $(".section").change(function() { if($(this).is(":checked")) { $("." + this.id).show(); ... Now, I am attempting to simulate a click event on the ch ...

Performing Batch Writes in Firestore using the Admin SDK

I have a massive ASCII flat file containing 1.5 million lines, which is essentially a list of parts from a manufacturer. I want to store this data in Firestore. Originally saved as a .csv file, the size was 250GB. After converting it to a JSON file using ...

The callback function was called twice after making a POST request

I am encountering an issue with my TypeScript code for processing Spotify's login flow. The code snippet is structured as follows: import * as React from 'react'; import '@patternfly/react-core/dist/styles/base.css'; import { useNa ...

What is the method for substituting one text with another using two-way data binding?

I implemented two different cases in my Mat-Table. When there is no data, the user will see a message saying "No Data Found". However, if the user enters text in the filter search, the "No Data Found" message should be hidden and replaced with the entered ...

Passing information to VueJS methods through Vue.js

This is the HTML code I have in my App.vue file. <b-form @submit="onSubmit"> <b-form-group> **nested v-model binding** <div v-for="(question, index) in questionsList" :key="question.question"> ...

Encountered an error while attempting a GET request to 'http://localhost:3000/': The resource failed to load, resulting in a net::ERR_CONNECTION_REFUSED error in delete.js

Every time I attempt to GET '/' through my express server, I encounter an error message indicating "Failed to load resource: net::ERR_CONNECTION_REFUSED ... delete.js". This issue typically arises when I try to submit a form from http://localhost ...

Data not being returned by AJAX request

I'm currently working on implementing a script in the background of my PHP pages to periodically check for new messages in the database and notify users accordingly. To achieve this, I decided to utilize AJAX to make a call to a file containing the n ...

How to automatically refresh the idToken in a Firebase http request when the currentUser object is null?

Currently implementing a Custom Auth System with React JS and Firebase for sign-in operations. The Back End generates a custom token, allowing the Front End to execute signInWithCustomToken. After successful sign in, an issue arises when refreshing the pa ...

Looking to generate flipcards dynamically through javascript or jquery when a button or link is clicked?

I've created flipping cards that flip on hover, but I'm struggling to add a button/link that generates a new flipcard when clicked. Any help would be greatly appreciated - plus, I'm new here! Here's my HTML and CSS code for the flipcard ...

What is the best way to create an array within an object during the parsing process

When working with a JSON object, I need to assign a value stored in the session against an ID. The JSON data is as follows: [ { "id": "a", "text": "a", "icon": true, "li_attr": { "id": "a" }, "a_attr": { "href": "#" ...

Attempting to interpret HTML in Javascript

I have a text string that contains HTML tags. Initially, I attempted to insert this using innerHTML, but the tags were displayed as plain text. After some troubleshooting, I realized that I needed to properly parse the HTML content. Although jQuery prov ...

Exploring vertex geometries in BufferGeometry within Three.js

Initially, I thought I wanted a simple, quiet solution, but it turned out to be more complex than I anticipated. All I'm aiming for are meshes on every vertex of a THREE.BufferGeometry (specifically a sphere)! You can view the CODEPEN here: codepen. ...

How can you make an Angular directive activate only after the scope function in an ng-click handler has been executed?

Scenario I am relatively new to Angular and facing a specific challenge. The goal is to make a directive change the color and add an image to a button. However, I am struggling to get the first if condition to work in my Angular Directive. Issue The ob ...

Refresh the source dropdown when the x-editable is shown

I need to update the source data for x-editable just before it is displayed in order to ensure that my dropdown menu always displays the most recent entries, even if the source has changed. For more information, you can visit: http://jsfiddle.net/XN7np/3/ ...

Using JavaScript, retrieve the ID of a child element by utilizing details about the parent element

I have implemented a JavaScript function that creates a div element. Within this div, there are multiple checkboxes as child elements. My goal is to use a loop to extract the ids of all these checkboxes. The div has been assigned to a variable named: o ...