sending data to Vue components during compilation

As I am working on mounting an htmlform element and recompiling it with some props, I encountered errors in the Console when trying to update the props. You can view the screenshot here.

 <script>
     //imports here

export default{
  props:['pma_posturl','pma_password','pma_username'],
  data: function(){
    return{
    domain:'',
    url:'',
    dbs:[],
    credentials:''
  }
},
methods:{
  //functions to get credentials
  getcredentials(){

    this.popup();
  },
  popup(){

     //update props values that Vue.js complains about  
     this.pma_username=this.credentials.database;
     this.pma_password=this.credentials.password;
     this.pma_posturl="URL"+this.credentials.database;

     console.log(this.pma_username); //correct value
     this.compile('dbform',this.props);
     $('#myform').submit();
},

 compile: function(refs,props){
        var tmp = Vue.extend({
          props: props,
          template: '<form  method="post" :action="pma_posturl"  id = "myform" ref="myform" name="login_form" target="_blank"><input type="text" name="pma_username" id="input_username" :value="pma_username"><input type="password" name="pma_password" id="input_password" :value="pma_password"></form>'
        });
        new tmp().$mount(this.$refs[refs]);
      }
}
}

</script>

Answer №1

To resolve the issue, you need to refactor the code by making the following changes:

    //adjusting values to prevent Vue JS error  
 this.pma_username=this.credentials.database;
 this.pma_password=this.credentials.password;
 this.pma_posturl="URL"+this.credentials.database;

 console.log(this.pma_username); //verified correct value
 this.compile('dbform',this.props);

Instead of the above code, create a new object using the props of the current component like this:

  let customprops={
                  'pma_posturl':"URL"+this.credentials.database,
                  'pma_password':this.credentials.password,
                 'pma_username': this.credentials.database
               }

   this.compile('dbform',customprops);

Answer №2

I had been passing the propsdata incorrectly before, but now it is fixed and working properly.

compile: function(refs,props){
        var tmp = Vue.extend({
          props: ['pma_posturl','pma_password','pma_username'],
          template: '<form ......>........</form>'
        });
        new tmp({
        propsData: props
      }).$mount(this.$refs[refs]);

The code has been updated and functioning as expected. However, it seems to be retaining older values from the first call even though I can see the new value in the console log.

 // console.log(props) /* it has the latest value */
 var vm = new tmp({propsData: props}).$mount(this.$refs[refs]);
 $('#myform').submit();
  vm.$destroy();

After logging the vm.$destory(), I am getting undefined. What could I be doing wrong in this scenario?

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

Extracting the href attribute from a child <a> tag

I am struggling to retrieve the value of the href within the code structure below: <div class=""> <div class=""> <div class=""> <a href=""><img src=""></a> </div> </div> </div> The m ...

The tilesloaded event in google.maps.event.addListener is unexpectedly failing to trigger

Today, while testing popover messages on my cordova/ionic app, I compiled the app and noticed that the maps weren't loading. Instead, only my custom "Loading map..." spinning icon kept showing. Upon investigating further, I found that var setMap = n ...

Transforming an Ext.data.TreeStore data structure into a JSON format

How can I convert an Ext.data.TreeStore to a string for saving to Local Storage? I tried using Ext.encode() but it's giving me a circular structure error. Has anyone encountered this issue and found a workaround? ...

Using the https module in Node.js to transfer a file to a PHP server

What is the best method to send an HTTP post request that includes a jpg file to a php server using the node https module? I attempted to use the request module, but it is unreliable (timing out most of the time) and already deprecated. Here is the functi ...

The canvas element automatically removes itself after being resized within an HTML5/JavaScript environment

I created a canvas that is interactive and responsive to screen size. However, I encountered an issue where the canvas clears itself when the browser is resized by just one pixel. Is there a way to prevent this from happening? I have included code in my sc ...

Removing a child component in Vue

I've written this code snippet: Vue.component('parent', { template: ` <div> <child v-for='(child, index) in children' :key='index' :childNumber="index+1" v-on:removeChild="removeChild" /> < ...

Is it possible to toggle the status of an item in JSON based on a counter value

Here is the JSON data I have: "questions": { "id": 1, "question": "Select one color", "answers": [ {"id": 1, "answer" : "Green", "isSelected" : false}, {"id": 2, "answer": "Red", "isSelected" : false}, ...

Jquery's intermittent firing of .ajax within if statement

So, I've inherited a rather messy codebase that I need to modernize. The task involves upgrading from an old version of prototype to the latest jQuery 3.2.1 within a dated website built on php and smarty templates (not exactly my favorite). When a lo ...

Cookie Consent has an impact on the performance of PageSpeed Insights

On my website, I have implemented Cookie Consent by Insights. The documentation for this can be found at However, I noticed a significant drop in my Google PageSpeed Insight scores after loading the JavaScript source for Cookie Consent. The main issue hig ...

What is the best way to send multiple input box values to a function set in the controller?

I am attempting to send the values of two input boxes to a single controller function. <div class="container" ng-controller="MainCtrl"> <div class="row"> <div class="col-lg-6"> <input type="text" ...

The smooth scroll feature is not functioning properly on the animated mouse-scroll down button

I've recently added an Animated Mouse Scroll Down button on my website. However, when I click the button, the smooth scroll feature is not working as expected. Important Note: I already have a separate button for navigating to the next section where ...

The JavaScript alert box cannot retrieve data from the PHP parent page

What am I missing? Here is the JavaScript code snippet: <script language="javascript"> function openPopup(url) { window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=n ...

Have you ever wondered why req.body returns as undefined when using body parser?

Every time I attempt to make a post request, I keep receiving an error message stating that req.body is returning as undefined. Below is the content of my server.js file: import express from 'express'; import bodyParser from 'body-parser&ap ...

Encountering Webpack issues following the transition to Next 13

Since updating Next to version 13, we've encountered issues with our application not building properly. It appears that webpack is having trouble with imports, exports, and potentially typescript. ../../libs/queries/src/lib/groq/searchFaq.ts Module pa ...

`Inability to remove item from array in Vue.js`

I've been struggling to understand why this feature isn't functioning as expected. I'm using sample code for reference, but it's not behaving the same way. When I click on the delete button, nothing happens even though it should remove ...

Transforming a NestJS/VueJS application into a Docker container

We are in the process of containerizing a NestJS REST API and a VueJS application using Docker. To achieve this, we have created a docker-compose.yaml file and two Dockerfiles: docker-compose.yml: version: '3.8' services: fox-deck-app: b ...

Is the create attachment function of the Microsoft Graph API not functioning properly?

I've been trying to create an attachment for my messages by following the documentation provided, but unfortunately, the API seems to be giving me some trouble. I referred to the document at for guidance. Below is the JavaScript code that I have bee ...

Receiving a 200 response code, however the controller's store() method is not being accessed

Recently, I made the decision to switch from using a form in a blade file to a Vue-based form that utilizes Axios for posting data. After making these changes, I encountered an issue where I receive a 200 response, but my controller's store() method i ...

Code for asynchronous routing in Node.js

My current setup involves using node with express version 4.0, and I've noticed a lack of information online (including in the documentation) regarding embedding asynchronous code within a route. With middleware, it's straightforward: app.use(& ...

organizing data using backbone marionette router

I am attempting to display the query string, but I am only receiving null as output. The query string I am using is http:://localhost/admin/brands?foo=bar and no matter what I try, queryString remains null. I even attempted /brands/?foo=bar with no succes ...