M
M
Morrowind2021-08-31 18:22:22
Vue.js
Morrowind, 2021-08-31 18:22:22

How to use Vue js 3 object properties?

Hey!
I can not figure out even with the documentation how to use the properties of the components.
I create an instance but alas I get "undefined"

More code.

const Start= {
    data(){
        return {
            show: true,
            short: 1
        }
    },
    methods: {
        async Start(){ 
           const app = Vue.createApp(MyComponent)
           console.log(app.count) <---- вот тут "undefined"
      }
    }
}

const MyComponent = ({
  data() {
    return { count: 4 }
  },
 methods: {
        TestMetod(){
              this.count++
        }
 }
})


Maybe I want a lot with this use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2021-08-31
@hekkaaa

const fragment = document.createDocumentFragment();
const app = createApp(MyComponent).mount(fragment);
console.log(app.count);
console.log(app.$data.count);

https://v3.vuejs.org/api/options-data.html#data-2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question