Do I need to pass data to a V model? Is it necessary to initialize the data if it is being passed from a different component

I need to assign the value of the content data from another component to the this.newTutorial.content push function. I successfully obtained the data, but now I am facing an issue with assigning it to my v-model. It's like transferring data from one v-model to another v-model. I attempted to do this in the created function:

this.newTutorial.content = this.content;
However, it resulted in an error stating "type check failed for prop 'rules'. Expected Array, got Boolean with value true."

Here is the code snippet:

<style scoped>
img.preview {
  width:200px;
}
.v-btn {
    height: 50px !important;
    min-width: 50px !important;
}

</style>

<template>

<div id="app">
    <v-dialog v-model="dialog" width="500">
        <template  v-slot:activator="{ on, attrs }">
            <v-btn style="z-index:9;" color="blue lighten-1" dark rounded v-bind="attrs" v-on="on" fixed left>
                <v-tooltip right >
                    <template  v-slot:activator="{ on, attrs }">
                        <v-icon fab dark v-bind="attrs" v-on="on">
                            mdi-plus
                        </v-icon>
                    </template>
                    <img class="monk-ico" src="https://celfonica.s3-us-west-1.amazonaws.com/logos/monk-circle+50px.png">
                    <span style="display:inline;">
                      Add Tutorial
                    </span>
                </v-tooltip>
            </v-btn>
        </template>
    ...

Then my component code for importing the content data:

<script>
export default {
  name: 'EditorContent',
  props: {
    editor: {
      default: null,
      type: Object
    },
    value: {
      default: "",
      type: String
    }
  },

  watch: {
    editor: {
      immediate: true,
      handler(editor) {
        if (!editor || !editor.element) return;

        this.editor.setContent(this.value);
        this.editor.on("update", ({ getHTML }) => {
          this.$emit("input", getHTML());
        });

        this.$nextTick(() => {
          this.$el.appendChild(editor.element.firstChild);
          editor.setParentComponent(this);
        });
      }
    },
    value: {
      handler(value) {
        this.editor.setContent(value);
      }
    }
  },
...

VUE data:

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

Console error:

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

Answer №1

It appears that you are exploring the implementation of two-way binding using v-model on a custom element.

In order to achieve this, you will need to establish a prop named content and then emit input events to the parent component. Take a look at the code snippet below for guidance:

Child component:

<template>
  <div class="date-picker">
    Month: <input type="number" ref="monthPicker" :value="value.month" @input="updateDate()"/>
    Year: <input type="number" ref="yearPicker" :value="value.year" @input="updateDate()"/>
  </div>
</template>

<script>
export default {
  props: ['value'],

  methods: {
    updateDate() {
      this.$emit('input', {
        month: +this.$refs.monthPicker.value,
        year: +this.$refs.yearPicker.value
      })
    }
  }
};
</script>

Parent component:

<template>
  <div class="wrapper">
    <date-picker v-model="date"></date-picker>
    <p>
      Month: {{date.month}}
      Year: {{date.year}}
    </p>
  </div>
</template>

<script>
import DatePicker from './DatePicker.vue';

export default {
  components: {
    DatePicker
  },

  data() {
    return {
      date: {
        month: 1,
        year: 2017
      }
    }
  }
})
</script>

For more insights, you can refer to this informative article

Answer №2

After troubleshooting, I found the solution by removing the content v-model inside the editor content tag and adding the v-model specifically created for sending tutorials. Below is the revised code snippet that worked successfully:

Revised Code:

<template>
<div>
<editor-content  label="Tutorial content"  :editor="editor" v-model="newTutorial.content" />
</div>
</template>

Inside the script in my data :

 newTutorial: {
                first: '',
                email: '',
                last: '',
                language: [],
                title: '',
                content: '',
                date: '',
                picture:'',
                code: '',
            },

Inside the script in my send function :

addTutorial: function() {
            messagesRef.child(this.newTutorial.userID).push(this.newTutorial);
            this.newTutorial.first = '';
            this.newTutorial.last = '';
            this.newTutorial.content = '';
            this.newTutorial.email = '';
            this.newTutorial.language = '';
            this.newTutorial.title = '';
            this.newTutorial.date = '',
            this.newTutorial.picture= '',
            this.newTutorial.code= '',
            toastr.success('Horray! message sent successfully');
            this.displayText = 'Nice job!';
            this.nameRules = true;
            this.emailRules = true;
            this.contentRules = true;
            this.titleRules = true;
        },

Data stored in the database:

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

Form component code:

<style scoped>
img.preview {
  width:200px;
}
.v-btn {
    height: 50px !important;
    min-width: 50px !important;
}

</style>

<template>

<div id="app">
    [...]
</div>

</template>

<script>
[...]

Hope this helps someone who is looking to integrate a tip tap editor successfully!

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

Exploring Event Listeners in the World of JavaScript and/or jQuery

Is there a more sophisticated way to monitor the execution of a specific function in JavaScript or jQuery? Instead of waiting for an event like $('#mything').click(function(){ //blah }), I prefer to be notified when a particular function is trig ...

Angular - connecting a function directly

Is there any potential performance impact of directly binding a function in directives like ng-show in AngularJS? <div ng-show="myVm.isVisible()"> .... </div> // controller snippet (exposed through controllerAs syntax) function myCtrl (myServ ...

A specific image is loading after being clicked in a new page

Despite my efforts to search on various platforms, I have not been able to find a comprehensive solution to my query. Scenario: I currently have a webpage containing a div with multiple images. These images load without any issues and are set to open in ...

What could have caused my javascript file to disappear from npm?

After creating a small library consisting of a .js file with commonly used functions, I placed it in the node_modules directory alongside my other packages. Everything seemed to be going well. A few days later, I decided to add a new package using npm ins ...

Type-safe Immutable.js Records with TypeScript

I'm struggling to find a suitable solution for my query. I am aiming to define data types using an interface in TypeScript, but my data consists of Immutable.js records making it more complex. Please refer to the example provided below. interface tre ...

Utilizing a SQL LIKE operator within a SELECT statement with Twitter/typeahead.js

Here is the code that I am working with: $places = query("SELECT * FROM places WHERE postal_code = ? or place_name = ? or admin_code1 = ? or admin_name2 = ? or admin_name1 = ?", $_GET["geo"],$_GET["geo"],$_GET["geo"],$_GET["geo"],$_GET["geo"]); When I st ...

The prototype chaining for JavaScript inheritance was not functioning as expected

I have been studying Stoyan Stefanov's book on JavaScript Patterns and I seem to be stuck...I am having trouble inheriting the prototype. What could I possibly be doing wrong? (Please execute this code in NodeJS) // implementing inheritance function ...

Troubleshooting Texture Compatibility Issue with ThreeJS ShaderMaterial on iOS Devices

Seeking assistance with shaders in Threejs. I have a plane that requires a mixture of 10 different textures; currently using ShaderMaterial and passing all textures for blending. Below is my Fragment Shader code: vec3 CFull = texture2D(tFull, vUv).rgb; vec ...

Guide on transferring Javascript array to PHP script via AJAX?

I need to send a JavaScript array to a PHP file using an AJAX call. Here is the JavaScript array I am working with: var myArray = new Array("Saab","Volvo","BMW"); This JavaScript code will pass the array to the PHP file through an AJAX request and displ ...

From Angular JS to Node Js with the help of the Express Js framework

I've been attempting to run an AngularJs front-end with a NodeJs server using ExpressJs. The main purpose of this program is to take user input and display it on the server console. With my limited JavaScript knowledge, I've put together the foll ...

Retrieve the Javascript variable and assign it to a PHP variable

When attempting to assign a JavaScript variable to a PHP variable and output the value in an alert, I am encountering an error. The output is shown as "; alert(simple); var p1sds = "My Custom String"; <?php $dsfd = "<script>document.writeln(p ...

"I am looking for a way to retrieve dynamic data from a (click) event in Angular. Can

Within my component, I have a video loaded in an i tag on a click event. The challenge is accessing the video ID from the video.component.ts file in order to dynamically load a new video. The solution has been elusive so far. <li *ngFor="let video of c ...

What is the best way to pass a selected item from a dropdown menu as an argument when calling a function from

Is there a way to achieve the following with AngularJS?: <select> <option ng-repeat="item in items" value="item">{{item.name}}</option> </select> <a ng-click="foo(item)">Action</a> The function foo is defined in an An ...

What categories do input events fall into within Vue?

What Typescript types should be used for input events in Vue to avoid missing target value, key, or files properties when using Event? For example: <input @input="(e: MISSING_TYPE) => {}" /> <input @keypress="(e: MISSING_TYPE) = ...

`Javascript framework suggests ajax navigation as the preferred method`

What is the best way to handle ajax navigation using jQuery? I have recently experimented with a simple jQuery ajax code to implement ajax-based navigation for all the links on a webpage. $('a').click(function(e){ e.preventDefault(); ...

Vue's watch function failing to trigger

Experiencing issues with Vue watch methods not triggering for certain objects even when using deep:true. Within my component, I am passed an array as a prop containing fields used to generate forms. These forms are dynamically bound to an object named cru ...

Tips on changing an image with a button click

I am currently working on a project where I have a div tag containing an image that is selected randomly from different arrays based on topics. However, I am facing some challenges in making the image change when the "go" button is clicked. I want the if ...

Utilize AJAX, jQuery, and Symfony2 to showcase array information in a visually appealing table format

I have a requirement to showcase data utilizing ajax and jQuery in a table on my twig file. The ajax call is made with a post request to the controller, where the controller attempts to input several rows from a csv file into the database. However, there ...

showing a pop-up message when a specific javascript function is triggered

Here is a unique code snippet showcasing a customized dialog box created with HTML, CSS, and JavaScript. The dialog box is displayed when a button is clicked. <!DOCTYPE html> <html> <head> <style> /* Custom Modal Styles */ .modal { ...

What could be causing my CSS and Bootstrap.css styles not to be implemented on my webpage?

While working on my Ruby on Rails application, I am trying to customize the design to resemble (which can be downloaded from ). However, I am facing an issue where the style sheets are not being applied. I have moved the style sheets from the bootstrap/c ...