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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

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

<div id="app">
  <div class="blog container">
    <h2 class="text-center mt-3">{{ header }}</h2>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addNewPost">
  Add Post
    </button>
<!-- Add post modal -->
    <div class="modal fade" id="addNewPost" tabindex="-1" role="dialog" aria-labelledby="addPostTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="addPostTitle">Add new post</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
            <div class="modal-body">
              <form>
                <div class="form-group">
                  <label for="title" class="col-form-label">Title:</label>
                  <input type="text" class="form-control" id="title" spellcheck="true" placeholder="Add title for new post here" v-model="newPost.title">
                </div>
                <div class="form-group">
                  <label for="shortText" class="col-form-label">Short Text:</label>
                  <input type="text" class="form-control" id="shortText" spellcheck="true" placeholder="Add short text for new post here" v-model="newPost.shortText">
                </div>
                <div class="form-group">
                  <label for="fullText" class="col-form-label">Full Text:</label>
                  <textarea class="form-control" id="fullText" spellcheck="true" placeholder="Add full text for new post here" v-model="newPost.fullText"></textarea>
                </div>
              </form>
            </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="addPost()">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    
<!-- Read post modal -->
    <div class="modal fade" id="readPost" tabindex="-1" role="dialog" aria-labelledby="readPostTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="readPostTitle">{{ readingPost.title }}</h5>
          </div>
            <div class="modal-body">
              <p class="text-body">{{ readingPost.fullText }}</p>
              <hr>
              <p class="col-form-label text-muted">Comments:</p>
              
              <div id="comment" class="bg-light">
                <p class="font-weight-bold m-0">Anonimous <i class="fa fa-window-close float-right"></i></p>
                <p class="text-body">This is 1st comment!</p>
              </div>
              
              <label for="commName" class="col-form-label font-italic">Your name:</label>
              <input type="text" class="form-control" id="commName" spellcheck="true" placeholder="Add your name here">
              <label for="addComment" class="col-form-label font-italic">Your comment:</label>
              <textarea class="form-control" id="addComment" spellcheck="true" placeholder="Add your comment here"></textarea>
              <button type="button" class="btn btn-primary m-2">Add comment</button>
            </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    
<!-- Edit post modal -->
 
<editmodal :post="post"></editmodal>
    
<!-- Card -->
    <hr>
    <div class="row card-columns">
       <div class="col-4 card mb-3 d-flex" v-for="(post, index) in posts"
                                            :key="index"
                                            :post="post"
                                            :index="index">
         <img src="http://placehold.it/300x150" class="card-img-top">
         <div class="card-body">
           <h3 class="card-title">{{ post.title }}</h3>
           <p class="card-text">{{ post.shortText }}</p>
           <div class="btn-group" role="group" aria-label="btn">
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#readPost" v-on:click="readPost(post)">Read More</button>
            <button type="button" class="btn btn-success" data-toggle="modal" data-target="#editPost" v-on:click="editPost(post, index)">Edit</button>
            <button type="button" class="btn btn-danger" v-on:click="deletePost(post)">Delete</button>
          </div>
         </div>
           <div class="card-footer">
            <small class="text-muted">0 comment</small>
           </div>
       </div>
    </div>
    
  </div>
</div>
              
            
!

CSS

              
                .col-4 {
  padding: 0;
}

.fa {
  font-size: 30px;
  visibility: hidden;
  cursor: pointer;
  transition: all ease-out 0.5s;
  opacity: 0;
}

#comment:hover .fa {
  visibility: visible;
  opacity: 0.9;
}
              
            
!

JS

              
                Vue.component('editmodal', {
    props: ["post"],
    template: `<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="editPostTitle">Edit post</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
            <div class="modal-body">
              <form>
                <div class="form-group">
                  <label for="title" class="col-form-label">Title:</label>
                  <input type="text" class="form-control" id="title" spellcheck="true" v-model="post.title">
                <div class="form-group">
                  <label for="shortText" class="col-form-label">Short Text:</label>
                  <input type="text" class="form-control" id="shortText" spellcheck="true" v-model="post.shortText">
                </div>
                <div class="form-group">
                  <label for="fullText" class="col-form-label">Full Text:</label>
                  <textarea class="form-control" id="fullText" spellcheck="true" v-model="post.fullText"></textarea>
                </div>
              </form>
            </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="saveEdit(post)">Save changes</button>
          </div>
        </div>
      </div>
    </div>`,

  methods: {
    saveEdit: function (post) {
       this.post = {
          'id': post.id,
          'title': post.title,
          'shortText': post.shortText,
          'fullText': post.fullText
        }
      // return this.post
    },
  },
});

new Vue({
  el: '#app',
  data () {
    return {
      header: 'Blog App',
      post: {},
      newPost: {},
      readingPost: {},
      posts: [ 
        { 
          id: 1,
          title: 'Title 1',
          shortText: 'some short-text 1',
          fullText: 'some full-text 1',
          comments: [{
            commName: '',
            commText: ''
          }
          ]},
        { 
          id: 2,
          title: 'Title 2',
          shortText: 'some short-text 2',
          fullText: 'some full-text 2' },
        { 
          id: 3,
          title: 'Title 3',
          shortText: 'some short-text 3',
          fullText: 'some full-text 3' },
        { 
          id: 4,
          title: 'Title 4',
          shortText: 'some short-text 4',
          fullText: 'some full-text 4' },
        ]
      }
    },
  // watch: {
  //   test: function (post) {
  //     this.post = post
  //   }
  // },
    methods: {
      deletePost: function (post) {
        console.log(post)
        this.posts.splice(this.posts.indexOf(post), 1)
      },
      addPost: function () {
        this.posts.push({
          'id': this.posts.length + 1,
          'title': this.newPost.title,
          'shortText': this.newPost.shortText,
          'fullText': this.newPost.fullText,
          'commName': '',
          'commText': ''
        })
        this.newPost = {}
      },
      readPost: function (post) {
        this.readingPost = {
          'id': post.id,
          'title': post.title,
          'shortText': post.shortText,
          'fullText': post.fullText
        }
      },
  
      editPost: function (post, index) {
        this.post = {
          'id': post.id,
          'title': post.title,
          'shortText': post.shortText,
          'fullText': post.fullText
        }
       },
      saveEdit: function(post) {
        this.post = post;
        return post;
        console.log(post)
      },
    }
});
              
            
!
999px
How do you comfort a JavaScript bug? You console it!

Console