Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <div id="app">
  <test-component />
</div>

<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-listener"></script>
              
            
!

CSS

              
                #app {
  text-align: center;
  font-family: sans-serif;
  font-size: 20px;
}
              
            
!

JS

              
                /*
  First create a Global API Class where you handel the
  Controller and Model parts, leaving all the code in
  Vue JS to act as the View.
  
  With this setup you get a complete MVC.
  Example with a global number, string and a bool.
  
  The class, for Controller and Model:
*/ 
class MyNameApi extends Listener {
  // Were using the constructor to set the vars up
  constructor() { 
    // call the Listener contructor first
    super();
    
    // set up a var you want to sync with the component
    // This is usually done in sub classes in the model
    this.name = '...';
    this.age = 0;
    this.ok = false;
    
    // Fake API call, using a timer
    const that = this;
    setInterval(() => {
      that.name = that.getNewName();
      that.age = Math.floor((Math.random() * 100) + 1);
      that.ok = !that.ok;
    }, 3000);
  }

  // Could be an external REST service, now it's just a random response
  getNewName() {
    const names = ['Lokes', 'Thor', 'Oden', 'Freya', 'Balder'];
    const num = Math.floor((Math.random() * names.length-1) + 1);
    return names[num];
  }
}

// Declare API to be used in Vue
const GlobalApi = new MyNameApi();

/*
  Here is the component with a template drawing the API response
  We include our Global API class and tie the 'name' var with 
  a Listener function.
*/
Vue.component('test-component', {
  data() {
    return {
      GlobalApi,
      name: 'not decided yet',
      age: 0,
      ok: false,
    };
  },
  template: '<p>👶<br>My name is {{name}}.<br>I\'m {{age}} years old, <br>and that\'s <span v-if="!ok">not</span> great...</p>',
  mounted() {
    // This is where the magic happens...
    // The Listen function in the Global API connects the
    // Component data.name with the Model name var
    // Insert more vars in the array to connect them all at once.
    this.GlobalApi.Listen(['name', 'age', 'ok'], this);
  },
});

// Start a new Vue app
new Vue({ el: '#app' });

              
            
!
999px

Console