Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<link href="https://code.jquery.com/ui/jquery-ui-git.css" rel="stylesheet" type="text/css" />
  <script src="https://code.jquery.com/jquery-git.js"></script>
  <script src="https://code.jquery.com/ui/jquery-ui-git.js"></script>
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <div id="app">
    <datepicker v-model="model.date"></datepicker>
    <datepicker v-model="model.date1"></datepicker>
    <input type="button" value="add" @click="submit" />
  </div>
  <script>
    Vue.component('datepicker', {
      props: ['value'],
      template: '<input type="text" />',
      mounted: function () {
        let vm = this
        $(this.$el).datepicker({
          dayNames: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
          dayNamesMin: ["日", "一", "二", "三", "四", "五", "六"],
          monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
          monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
          prevText: "上月",
          nextText: "次月",
          weekHeader: "週",
          showMonthAfterYear: true,
          dateFormat: "yy-mm-dd",
          onSelect: function (date) {
            vm.$emit('input', date) //注意一下裡面的this是jquery對象的部份,所以定義一個vm變數代表vue的實體
          }
        })
      }
    })
    let vue = new Vue({
      el: '#app',
      data: {
        model: {
          date: '',
          date1: ''
        }
      },
      methods: {
        submit: function () {
          console.log(this.model.date)
          console.log(this.model.date1)
        }
      }
    })
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers