Skip to content

Use method from child component in parent with CDN vue.js #1313

@matthiasstorr

Description

@matthiasstorr

Hello,

I just switchend from alpine.js to vue.js (cdn) because i experiment with async frunctions.
My goal is to call a method from the parent which is defined in a component.

But when i want to call "test()" in my html file i get the error that _"Cannot read properties of undefined (reading 'childRef')"
All works fine when the method is defined at the "app" -element (parent) but i dont want to clutter this element with different mehtods.

Thanks in advance for every hint or remarks to my code.

Code Snippet

--------------------------------------
const app = Vue.createApp ({
  data() {
    return {
      visible: false,
      openTab: ''
    }
  },
  methods: {
    test() {
      this.$resfs.childRef.getMyDevices();
    }
  }
})
--------------------------------------
app.component('child',{
  data() {
    return {
      myDevices: {},
    }
  },
  methods: {
    async getMyDevices() {
      const response = await foo.getMyDevices();
      const data = await {...response.devices};

      this.myDevices = data;
    }
  },
  template: `<div ref="childRef"></div>`
})
´´´

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions