Home > Back-end >  How to receive data in root component with method?
How to receive data in root component with method?

Time:10-24

I want to understand how Vue works. What I am trying approach is simply to receive number '1' with method in Vue. Code execution gives me 'undefined'. Why?

<div id="form">
    <button v-on:click="submitProduct">Save</button>
</div>
<script>
    var someForm = Vue.createApp ({
    methods: {
        submitBtn: function(){
            someForm.showdata
        },
        showData: function(){
            return 1
        }
    }
})
</script>

CodePudding user response:

Try to assign the returned data to a variable then show it using alert or console.log a,d use this instead of someForm:

    var someForm = Vue.createApp ({
    methods: {
        submitBtn: function(){
          let data=  this.showData();
           alert(data);
        },
        showData: function(){
            return 1
        }
    }
})
  • Related