With Vue ^3.3, you can now use console
directly in the template:
<template>
<!-- just works, no more `console` doesn't exist -->
<button @click="console.log">Log</button>
</template>
If using Vue prior to 3.3, do:
const app = createApp(App)
app.config.globalProperties.console = console
If also using TypeScript:
// types.d.ts
export {}
declare module 'vue' {
interface ComponentCustomProperties {
console: Console
}
}
If using Vue 2, do:
Vue.prototype.console = console
Use console.*
inside the template:
<h1>{{ console.log(message) }}</h1>
To not interfere with the rendering, use console.*
with ??
(or ||
if using Vue 2, since ??
is not supported in the Vue 2 template):
<h1>{{ console.log(message) ?? message }}</h1>
vue-class-component
, simply addingconsole = console;
in your class definition will work; – Utta