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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
  
</head>
<body>
<div id="app">
  <p>請輸入使用者名稱。</p>
  <input type="text" v-model="userName">
  <p>{{errMsg}}</p>
</div>
</body>
</html>
 
var vm = new Vue({
  el: '#app',
//   delimiters: ['${', '}'],
  data: {
    userName: '',
    errMsg: ''
  },
  watch: {
    //當userName更動後,就會觸發check這個method
    userName: function(value) {
      if(this.check(value)) {
        this.errMsg = '使用者名稱開頭不可為數字。'
      } else {
        this.errMsg = '合法的使用者名稱。';
      }
    }
  },
  methods: {
    check: function(name) {
      return /^[0-9]/.test(name);
    }
  }
});
Output

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

Dismiss x
public
Bin info
chun-wenpro
0viewers