1

I saw many answers telling to use vue-devtools to access the Vue Object but is there a way to do it in the browser console? Like in the tutorial, we enter

> app.data.sock

in console to get the data

Let's say:

main.js

import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')

App.vue

<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <HelloWorld />
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

export default {
  name: 'App',
  components: {
    HelloWorld
  }
}
</script>

HelloWorld.vue

<template>
  <div class="hello">
    <ul>
      <li v-for="title in titles" :key="title.id">{{ title.name }}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      titles: [{
        id: 0,
        name: "a"
      },
      {
        id: 1,
        name: "b"
      }]
    }
  }
}
</script>

How do I access the data of 'titles' in HelloWorld.vue? In other word, how to get this.data.titles[0].name in the HelloWorld.vue in the browser console? Thank you

3
  • please paste complete component code Commented Dec 12, 2020 at 16:09
  • maybe here stackoverflow.com/questions/51848439/… are talking about you :) Commented Dec 12, 2020 at 16:12
  • @AliasgherNooruddin edited Commented Dec 13, 2020 at 4:02

1 Answer 1

1

You can access the value of data function in created our mounted hooks of Vue lifecycle or can create a function in methods. I am calling your data in created hook


<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      titles: [{
        id: 0,
        name: "a"

      },
      {
        id: 1,
        name: "b"
      }]
    }
  },
 created(){
     console.log(this.data.tiles)
  }
}
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

to learn more about mounted and created see this
Yes, but is there a way to it on the browser itself? For example entering this.data.titles[0].name in the browser console and it will reply a
No its not possible install vue dev tools there you can check vue objects whenever you want

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.