zoukankan      html  css  js  c++  java
  • 6.自定义私有指令

    1.自定义私有指令:

    <div id="app2">
     <h3 v-color="'pink'" v-fontweight="900" v-fontsize="50">{{ dt | dateFormat }}</h3>
    </div>

    实现:

    var vm2 = new Vue({
          el: '#app2',
          data: {
            dt: new Date()
          },
          methods: {},
          directives: { // 自定义私有指令
            'fontweight': { // 设置字体粗细的(第一种写法)
              bind: function (el, binding) {
                el.style.fontWeight = binding.value
              }
            },
            'fontsize': function (el, binding) { // 注意:这个 function 等同于把代码写到了 bind 和 update 中去(第二种写法)
              el.style.fontSize = parseInt(binding.value) + 'px'
            }
          }
    })
    

     

  • 相关阅读:
    5月16日 AJAX
    5月13日 Jquery基础
    5月13日 PDO封装
    会话控制练习
    文件上传
    会话控制
    注册审核
    练习
    三级联动
    AJAX之XML
  • 原文地址:https://www.cnblogs.com/yaboya/p/10246003.html
Copyright © 2011-2022 走看看