Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda