エッセイ:Vueのカスタムコマンド

692 ワード

カスタムグローバルコマンド:
//         v-focus,            :

    Vue.directive('focus', {

      inserted: function (el) { // inserted                

        el.focus();

      }

    });

カスタムローカルコマンド:
//         v-color   v-font-weight,                      :

      directives: {

        color: { //             

          bind(el, binding) {

            el.style.color = binding.value;

          }

        },

        'font-weight': function (el, binding2) { //           ,       bind   update       

          el.style.fontWeight = binding2.value;

        }

      }

カスタムコマンドは呼び出し時にv-を追加する必要があります.定義時にv-を追加する必要はありません.