Skip to content

Instantly share code, notes, and snippets.

@ceme
Created September 8, 2017 05:39
Show Gist options
  • Save ceme/4642cb24fe935a020a7dbb6ad554b6b6 to your computer and use it in GitHub Desktop.
Save ceme/4642cb24fe935a020a7dbb6ad554b6b6 to your computer and use it in GitHub Desktop.
vuejs : Bind visibility
<!doctype html>
<html>
<head>
<title>vuejs : Bind visibility</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 21px Helvetica, Arial; }
span::after {
content: '';
display: block;
clear: both;
}
</style>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<!-- Bind visibility -->
<div id="app">
<p v-if="showme">Now you see me</p>
<button v-on:click='toggleMessage'>{{buttonMessage}}</button>
</div>
<script>
var app3 = new Vue({
el: '#app',
data: {
showme: true,
buttonMessage: "Hide Message"
},
methods: {
toggleMessage: function() {
this.showme = !this.showme;
this.buttonMessage = this.getMessage();
},
getMessage: function() {
return this.showme ? "Hide Message" : "Show Message";
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment