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>Components (cont.)</h2>

<div id="my-app">
 <!-- registered as MyAlbum on the main instance -->
 <!-- any 2+ word length prop will be used as kebab-case here too -->
 <my-album v-for="(album, index) in discography" :key="index" :name="album.name" :cover="album.cover"
  :release-date="album.releaseDate"></my-album>
</div>

<!-- Externally defined template -->
<script type="text/x-template" id="my-album">

 <div class="card">
  <img :src="cover" alt="album image goes here">
  
  <p>
   <span class="label">Album name: </span>
   <br>
   <span class="value">{{name}}</span>
  </p>
  
  <p>
   <span class="label">Release date:</span> 
   <br>
   <span class="value">{{releaseDate}}</span>
  </p>
  
 </div>

</script>
              
            
!

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 {
 background-color: whitesmoke;
 color: #34495e;
 margin: 10px 0;
 padding: 5px;
}

/* component styles */
.card {
 display: flex;
 align-items: center;
 justify-content: space-around;
 box-shadow: 3px 4px 25px -4px rgba(0, 0, 0, 0.38);
 margin: 15px 0;
 padding: 5px;
 background-color: lightgoldenrodyellow;

 img {
  width: 100px;
  box-shadow: 5px 4px 25px -4px rgba(0, 0, 0, 0.38);
 }

 p {
  margin: 10px;
 }

 .label {
  font-weight: bold;
 }

 .value {
  font-style: italic;
 }
}

              
            
!

JS

              
                // The data we want to show
const discography = [
    {
        cover: 'https://upload.wikimedia.org/wikipedia/en/c/c0/PleasePleaseMe_audio_cover.jpg',
        name: 'Please Please Me',
        releaseDate: '22 March 1963'
    },
    {
        cover: 'https://upload.wikimedia.org/wikipedia/en/e/e7/Help%21_%28The_Beatles_album_-_cover_art%29.jpg',
        name: 'Help!',
        releaseDate: '6 August 1965'
    },
    {
        cover: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/TheBeatles68LP.jpg/440px-TheBeatles68LP.jpg',
        name: 'White Album',
        releaseDate: '22 March 1963'
    }
];

// This component will be locally registered, 
// so we can create a variable which contains 
// all the component properties and use it later
const MyAlbum = {
    // components can additionally have props
    // this is a way to pass in the data
    // and the simplest syntax is an array of prop names
    props: ['cover', 'name', 'releaseDate'],
    // alternative to defining the entire template inline 
    // is to use an externally defined template
    template: '#my-album'
};

// this is the main instance
// or the root of the app
new Vue({ 
    el: '#my-app',
    data: {
        discography
    },
    // registering the component locally
    components: {
        // Vue will convert this notation to kebab-case
        MyAlbum
    }
});
              
            
!
999px

Console