Open4

Vue.jsまとめ

ターボターボ

フレームワークとライブラリの違い

フレームワーク

アプリケーションの設計

ライブラリ

特定の機能を持つプログラム
文字列、日付、アニメーションなど関数を備えている

ターボターボ

インスタンスとクラス

クラス

class Person{
 constructor(name,age){
  this.name=name;
  this.age=age;
 }
}

インスタンス

const Taro=new Person('Taro',24);
console.log(Taro); 

Vueクラスのインスタンス化

<body>
 <div id="app">
  <p>{{text}}</p>
 </div>
</body>
new Vue({
 el: '#app',
 data(){
  return{
   text:'Hello vue.js'
  };
 }
});
ターボターボ

フォーカス当たったら表示

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>

  </style>
</head>
<body>
  <div id="app">
    <input type="email" @focus="emailf">
    <div v-show="show">表示されています</div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el:'#app',
      data(){
        return {
          show:false
        }
      },
      methods:{
        emailf(){
          this.show=true;
        }
      }
    });
  </script>
</body>
</html>
ターボターボ

#バインディング

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .emailinput{
      display: block;
      width: 70vw;
      height: 40px;
      margin: 10px auto;
      background-color: #345730;
      color: white;
      text-align: center;
    }
    .form-email{
      display: block;
      width: 70vw;
      height: 40px;
      margin: 10px auto;
      background-color: #9979f1;
      color: #579D96;
    }
  </style>
</head>
<body>
  <div id="app">
    <input type="email" @focus="emailf" class="emailinput" v-bind:class="{'form-email':formemail}" v-model="emailmpdel">
    <div v-show="show">表示されています</div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el:'#app',
      data(){
        return {
          show:false,
          formemail:false,
          emailmpdel:'メールアドレス'
        }
      },
      methods:{
        emailf(){
          this.show=true;
          this.formemail=true;
          this.emailmpdel='';
        }
      }
    });
  </script>
</body>
</html>