Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log is not working inside vue.js script

I am quite new to vue.js, and I am trying to build an basic application that displays data fetched from an API.

I do not understand why I cannot use console.log inside my scripts :

<script>

    import Header from './components/layout/Header.vue'
    import Todos from './components/Todo.vue'

    export default {
      name: 'app',
      components: {
        Todos,
        Header,
      },
      data () {
        return {
          todos : []
        }
      },
      methods : {

        created () {
            fetch('https://jsonplaceholder.typicode.com/todos')
            .then( resp => resp.json())
            .then( data => {

                console.log(data);
            })
            .catch(err => err)

        }
      }
    }
</script>

I always got "unexpected console statement"

Does anybody knows how I can console log stuff inside vue scripts ? Am I missing something ??

Thanks a lot !!

like image 203
Jonas Avatar asked Aug 12 '26 16:08

Jonas


1 Answers

You can try

methods: {
 log(msg){
  console.log(msg); 
 }
}

And when you want to write things to console, use:

{{ log(message) }}
like image 50
cengiz sevimli Avatar answered Aug 15 '26 00:08

cengiz sevimli