1

If I need to test an element and see what's happening at console. I'm defining a method and call it in a template like this.

<template>
  <button @click="logHello()"> My Button </button>
</template>

<script>
  methods: {
    logHello(){
      console.log('Hello world')
    }
  }
</script>

But I don't want to define a method at each time I need to log something. Is there is a way to log something just using template and not writing anything in an instance like this:

<button @click="console.log('Hello')"> My Button </button>

I know this one is not working but I'm looking for something similar.

1

2 Answers 2

-1

in your template use two curly braces like this {{console.log('hello')}}

Sign up to request clarification or add additional context in comments.

Comments

-1

It is very simple, but not very recommended. To issue a console.log directly in the template you can use:

this.console.log('test')

For example:

<button @click="this.console.log('Hello')"> My Button </button>

I hope I helped in some way

1 Comment

That doesn't work: [Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of null (reading 'console')"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.