How can I get access to a component's data via a window.addEventListener? I want to hit the 'g' key and hide the Vue component test.
JS:
window.onload = function () {
Vue.component('test', {
template: `<div id="box" v-if="visible"></div>`,
data() {
return {
visible: true
}
}
})
var app = new Vue({
el: '#app'
});
window.addEventListener('keydown', (e) => {
if (e.key == 'g') {
//set test.visible = false
}
});
window.app = app;
}
HTML:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="code.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="app">
<test></test>
</div>
</body>
</html>