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

              
                #buylist
  h1 我的購物清單
  .title
    label 產品
    input(placeholder="Name" ref="input_name")
    label 數量
    input(type="number" placeholder="How many" ref="input_quantity" )
    label 價錢
    input(type="number" placeholder="How much" ref="input_price" )
    span.add(@click="addList") +新增
  .choose
    button(:class="[show === 'all'? 'menu' : '']" @click="show = 'all'") All
    button(:class="[show === 'done'? 'menu' : '']" @click="show = 'done'") completed
    button(:class="[show === 'undo'? 'menu' : '']" @click="show = 'undo'") undo
  .itemlist
    ul
      li(v-for="todo in filterTodos" :class="{ active: todo.completed }" :key="todo.timestamp") 
        template(v-if="editing === todo")
          input(class="name" type="text" v-model="editingName")
          input(class="quantity" type="number" min=1 v-model="editingQuantity")
          input(class="price" type="text" v-model="editingPrice")
          button(@click="completeHandler") 完成
          button(@click="cancelHandler") 取消
        template(v-else)
          input(type="checkbox" v-model="todo.completed")
          label.name {{todo.name}}
          .quantity(:value="todo.quantity") {{todo.quantity}}
          .price(:value="todo.price") {{ todo.price | filterComma | priceFormat }}
          .edit(@click="editHandler(todo)") Edit
          .del_btn(@click="removeList(todo)") X
      label.total Total : {{getTotal | filterComma | priceFormat}}
      .allDone(@click="allDone") All Done
//p.made ---- By Sung Chian ----

              
            
!

CSS

              
                $color_black: #444
$color_yellow: #FFC954
$color_red: #0EBEFF
$color_white: #f3f3f3
$color_blue: #02ABFB
$color_pink: #E6036D
*
  // border: solid 1px
  // position: relative
  font-family: 'Amatic SC', sans-serif, "微軟正黑體"
  font-weight: 700
  font-size: 20px
  user-select: none
html,body
  width: 100%
  height: 100%
  margin: 0
  display: flex
  justify-content: center
  align-items: center
  background: linear-gradient(45deg, $color_red 0%,#F97C02 50%,$color_yellow 100%)
 
.made
  // display: flex
  flex-direction: column
  align-items: center
#buylist
  position: relative
  // display: inline-block
  padding: 10px
  border: solid 5px $color_black
  background-color: $color_white
  h1
    font-size: 30px
    text-align: center
    letter-spacing: 10px
    padding: 5px
    margin: -10px
    border-bottom: solid 5px $color_black
    color: $color_white
    background-color: $color_red
  .choose
    text-align: center
    .menu
      color: $color_red
    button
      width: 30%

.title
  margin-top: 30px
  background-color: $color_white
  //border: solid 2px $color_black
  padding: 5px
  input
    text-align: center
  .add
    border: solid 1px $color_black
    margin-left: 15px
    border-radius: 8px
    cursor: pointer
    &:hover
      background-color: $color_red
      color: $color_white
.itemlist
  background-color: $color_white
  display: inline-flex
  position: relative
  .total
    // position: relative
    font-size: 30px
    color: $color_red
    letter-spacing: 3px
    // display: block
  ul
    border: solid 2px
    width: 600px
    justify-content: space-between
    padding: 0
  li.active
    text-decoration: line-through
  .allDone
    position: absolute
    border: solid 1px $color_red
    border-radius: 20px
    font-size: 25px
    display: inline-block
    cursor: pointer
    background-color: $color_red
    color: $color_white
    user-select: none
    bottom: -10px
    right: 10px
    &:active
      border: solid 1px $color_yellow
      background-color: $color_yellow
      color: $color_red
  li
    border-bottom: solid 1px
    list-style: upper-roman
    position: relative
    display: flex
    justify-content: flex-start
    flex-wrap: wrap
    .name
      font-size: 25px
      flex-basis: 40%
      overflow: hidden
    .quantity
      font-size: 25px
      flex-basis: 10%
      width: 10%
      padding-left: 10px
      overflow: hidden
    .price
      font-size: 25px
      flex-basis: 25%
      overflow: hidden
    .edit
      font-size: 25px
      flex-basis: 10%
    input
      // text-align: center
    .del_btn
      display: inline-block
      position: absolute
      text-align: center
      right: 20px
      top: -3px
      padding: 0px 6px
      cursor: pointer
      font-family: 'Baloo Chettan 2', sans-serif
      &:hover
        //background-color: $color_red
        color: $color_red
              
            
!

JS

              
                var app = new Vue({
  el: "#buylist",
  data: {
    todos: [
      { name: "iphone", quantity: 1, price: 30000, completed: false, timestamp: 1 },
      { name: "ipad", quantity: 1, price: 22000, completed: false, timestamp: 2 },
      { name: "airpods", quantity: 1, price: 5290, completed: false, timestamp: 3 },
      { name: "airpods pro", quantity: 1, price: 7990, completed: false, timestamp: 4 },
      { name: "macbook", quantity: 1, price: 58000, completed: false, timestamp: 5 },
      { name: "macbook pro", quantity: 1, price: 89999, completed: false, timestamp: 6 }
    ],
    totalPrice: "",
    show: "all",
    editing: null,
    editingName: "",
    editingQuantity: "",
    editingPrice: "",
  },
  methods: {
    addList() {
      if(this.$refs.input_name.value===""){
        alert("your name is empty!!");
      }else if(this.$refs.input_quantity.value===""){
        alert("your quantity is empty!!");
      }else if(this.$refs.input_price.value===""){
        alert("your price is empty!!");
      }else{
        this.todos.push({
        name: this.$refs.input_name.value,
        quantity: parseInt(this.$refs.input_quantity.value),
        price: parseInt(this.$refs.input_price.value),
        completed: false,
        timestamp: new Date().getTime(),
      });
      // this.input_name.value = ""; //這邊綁model才有用
      this.$refs.input_name.value = "";
      this.$refs.input_quantity.value = "";
      this.$refs.input_price.value = "";
      }
    },
    removeList(todo) {
        this.todos = this.todos.filter((target) => {
        return target != todo;
      // this.$delete(this.todos, index);
    })
    },
    // removeList(index) {
    //   this.$delete(this.todos, index);
    // },
    allDone(){
      for(var j=0;j<this.todos.length;j++){
        if(this.todos[j].completed===false){
          this.todos[j].completed = !this.todos[j].completed;
        }
      }
    },
    editHandler(todo){
      this.editing = todo
      this.editingName = todo.name
      this.editingQuantity = todo.quantity
      this.editingPrice = todo.price
    },
    completeHandler(){
      if(this.editingName === ""){
        alert("nonono")
        return false
      }else{
        this.editing.name = this.editingName
      }
      if(this.editingQuantity < 1 || this.editingPrice < 0){
        alert("number is too low")
        return false
      }else{
        this.editing.quantity = parseInt(this.editingQuantity)
        this.editing.price = parseInt(this.editingPrice)
      }
      this.cancelHandler()
    },
    cancelHandler(){
      this.editingName = ""
      this.editingQuantity = ""
      this.editingPrice = ""
      this.editing = null
    } 
  },
  filters: {
    priceFormat: function(value) {
      return "$" + value;
    },
    filterComma(value2) {
      return value2.toLocaleString("en-US");
    }
  },
  computed: {
    filterTodos(){
      if(this.show === 'all'){
        return this.todos
      }
      else if(this.show === 'done'){
        return this.todos.filter((todo)=>{
          return todo.completed === true
        })
      }
      else if(this.show === 'undo'){
        return this.todos.filter((todo)=>{
          return todo.completed === false
        })
      }
      else{
        return []
      }
    },
    getTotal() {
      var sum = 0;
      for (var i in this.filterTodos) {
        sum += this.filterTodos[i].price * this.filterTodos[i].quantity;
      }
      return sum;
    },
  }
});

              
            
!
999px

Console