Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Welcome to Vue!</h1>

<h2>Watchers</h2>

<!-- declaring a mounting point -->
<div id="my-app">

 <h4>Pick one</h4>

 <p>
  Your favorite is: {{ myFavoriteFlavor }}
 </p>

 <div v-for="(flavor, index) in flavors" :key="flavor">
  <input type="radio" v-model="myFavoriteFlavor" :id="`fav-b-${flavor}`" name="my-favorite-flavor" :value="flavor">
  <label :for="`fav-b-${flavor}`">{{ flavor }}</label>
 </div>

 <!-- using this to show changes -->
 <div v-show="output">
  <!-- you can use expressions directly -->
  <button @click="output = ''">Clear output</button>
  <p class="output">
   <!-- v-html is another built-in directive -->
   <code v-html="output"></code>
  </p>
 </div>

</div>
              
            
!

CSS

              
                $primary: #41B883;
$secondary: #34495E;

body {
  background-color: whitesmoke;
  color: $secondary;
  font-family: sans-serif;
  padding: 10px;
}

h1 {
  margin: 0 auto;
  width: 80%;
  text-align: center;
}

h2, h3 {
    color: $primary;
}

#my-app {
  width: 80%;
  margin: 0 auto;
}

input[type=text] {
  color: $secondary;
  font-size: 1em;
  min-width: 250px;
  background: transparent;
  margin-bottom: 20px;
}

.answer {
  color: $primary;
}

.colored {
 background-color: $secondary;
 color: $primary;
}

hr {
 border: 1px solid $secondary;
 margin-top: 20px;
}

.off-limits {
 background: tomato;
 width: 100px;
 height: 100px;
 color: whitesmoke;
 font-weight: bold;
}

button {
 height: 2em;
 background: whitesmoke;
 font-size: 1.1em;
 border: 1px solid $secondary;
 margin-top: 5px;
 
 &:hover {
  background: $secondary;
  color: whitesmoke;
 }
 
 
}

.output {
 background: #7a7a7a;
 color: whitesmoke;
 padding: 12px;  
}

              
            
!

JS

              
                // creating a Vue instance
new Vue({
  // mounting it
  el: '#my-app', 
  // exposing data to the view
  data: { 
   // make sure these are set here before you want to use them
   // in the template or the method
   flavors: ['Chocolate', 'Vanilla', 'Strawberry', 'Cookies n Creme'],
   myFavoriteFlavor: null,
   // this will be used instead of the console.log
   output: ''
  },
 
  // watchers:
  watch: {
   // we have access to the old value as well as the new one
   myFavoriteFlavor(newVal, oldVal) {
    
    if (newVal === 'Cookies n Creme') {
     alert('Mine too!')
    }
    
    // just adding another line to the output
    // so we can show it inside of the app
    // instead of `console.log()`ing it
    this.output += `> Previously ${oldVal}, now: ${newVal} <br>`

   }
  }
 

})
              
            
!
999px

Console