JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script>
<div id="app">
{{ message }}
</div>
CSS
body {
margin: 0;
}
#app {
display: flex;
justify-content: center;
align-items: center;
color: red;
font: bold 48px monospace;
height: 100vh;
}
JavaScript
new Vue({
el: '#app',
data: () => ({
isWidthOK: false,
}),
computed: {
message() {
return this.isWidthOK ? 'hello, world!!' : 'fuck the world';
},
},
created() {
const mql = window.matchMedia('(max-width: 600px)');
const onChange = () => this.isWidthOK = mql.matches;
onChange();
mql.addEventListener('change', onChange);
this.$once('hook:beforeDestroy', () => mql.removeEventListener('change', onChange));
},
});