Vue

by ken3desu

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/zxcvbn/4.4.2/zxcvbn.js"></script>
<div id="app">
  <label for="password">パスワード: 
  <input type="text" @input="change($event)" @change="change($event)" v-model="password"></label>
  <br>
  <span>強度 : {{ score }}</span>
  <ol>
    <li class="warn">{{ warn }}</li>
    <li v-for="sug in suggestions">
    <span>{{ sug }}</span>
    </li>
  </ol>
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}
.warn {
  color: red;
}
#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

Vue

new Vue({
  el: "#app",
  data: {
    password: '',
    warn: '',
    score: '',
    suggestions:[],
  },
  methods: {
  	change: function($event){
      const zxc = zxcvbn($event.target.value);
      this.score = zxc.score;
      this.warn = zxc.feedback.warning;
      this.suggestions = zxc.feedback.suggestions;
    }
  }
})