Created
April 11, 2017 02:52
-
-
Save harishkotra/f74354135d88a415757775c6ee5bde3e to your computer and use it in GitHub Desktop.
Vue.js - Using v-if and v-else to display a different message to the user based on what is typed in the input field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <!-- just any other regular html tag --> | |
| <title>Vue Demo App with v-if & v-else directives</title> | |
| <!-- Fetch vue.js from the following library --> | |
| <!-- Other alternatives are to download the original library from https://vuejs.org/ --> | |
| <script src="https://unpkg.com/vue"></script> | |
| <style> | |
| #app { | |
| font-family: 'Montserrat', Helvetica, Arial, sans-serif; | |
| -webkit-font-smoothing: antialiased; | |
| -moz-osx-font-smoothing: grayscale; | |
| text-align: center; | |
| color: #2c3e50; | |
| margin: 20px; | |
| font-size:26px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <!-- | |
| Element to play around using vue. | |
| "app" is used in the javascript written below to add text and perform relevant actions. | |
| --> | |
| <div id="app"> | |
| <h4 v-if="!message">Enter text below to send.</h4> | |
| <h4 v-else>Click Go to send!</h4> | |
| <form action=""> | |
| <textarea name="message" v-model="message" id="" cols="30" rows="10"></textarea><br> | |
| <button v-show="message">Go</button> | |
| </form> | |
| </div> | |
| <script> | |
| //app is assigned to the Vue instance. | |
| //Vue accepts el and data to target the div. | |
| var app = new Vue({ | |
| el: "#app", | |
| data: { | |
| message: '' | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment