Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to get out the data from created application with method in VUE 3

When starting page, this happens:

  1. console.log(products.showData()) shows undefined
  2. Uncaught TypeError: products.showData is not a function
  3. Uncaught (in promise) TypeError: products.productList is undefined

All what I wanted is just return 1 with showData method. Can anybody please tell me what's wrong in this code?

<script>
var products = Vue.createApp ({
            el:"#products",
            data: function() {
                return {
                    productList: [],
                    product: {
                        sku: 0,
                        name: '',
                        price: 0,
                        attr: {
                            size: 0,
                            weight: 0,
                            dimensions: {
                                h: 0,
                                w: 0,
                                l: 0
                            }
                        }
                    }
                }
            },

            components: ['sku'],
            methods:{
                addProduct: function(){
                    this.productList.push(this.product)
                    console.log(this.productList[0]['sku'])
                },
                showData: function(){
                    return '1'
                }
            }
        })
        
        products.mount("#products")
        
        products.component('product', {
            template: `
                <span>
                {{ this.sku }}<br>
                {{ this.name }}<br>
                {{ this.price }}<br>
                {{ this.size }}
                </span>
            ` ,
            data: function(){
                return {
                    'sku': products.productList[0]['sku'],
                    'name': 'name',
                    'price': 100,
                    'size': 10
                }
            }
        })
        
    console.log(products.showData())
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Application instance isn't root component instance. In order to access a component, a reference should be additionally stored.

As the documentation shows:

const app = Vue.createApp(RootComponent)
const vm = app.mount('#app')

Then vm is supposed to have showData, etc.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!