I have a boolean JavaScript variable tied to a Vue instance. When I change that boolean, Vue doesn't see the change. But when I declare a boolean in Vue from the beginning, Vue does see the change. Why the difference?
In my example Vue doesn't see someBoolean changing. It does see vueBool changing. Clicking the button should flip both boolean variables.
JavaScript:
let someBoolean = true;
let vInstance = new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!',
vueBool: true,
vSomeBoolean: someBoolean
}
})
document.getElementById("btnBooleanToggle").addEventListener("click", function(){
somBoolean = !someBoolean;
vInstance.vueBool = !vInstance.vueBool;
})
HTML
<script src="https://unpkg.com/vue"></script>
<div id="app">
<p>{{ message }}</p>
<p>
Boolean declared inside Vue: {{vueBool}}
</p>
<p>
Boolean declared outside Vue: {{vSomeBoolean}}
</p>
<button id="btnBooleanToggle">
Toggle booleans
</button>
</div>