• Vue指令运用


     Vue指令运用(数据加载Loading功能、降低对代码的侵入性)

    <html>
    <head>
      <meta charset="utf-8"/>
      <title>Vue指令</title>
    </head>
    <style>
      .bgpink{
        background-color: pink;
        width:150px;
      }
      .f{display: flex;}
      .xc{justify-content: center;}
      .ac{align-items: center;}
    </style>
    <body>
      <div id="root" v-loading="isLoading">
        <div>{{data}}</div>
        <div class='bgpink f ac xc' @click="update">点击更新</div>
      </div>
    </body>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
      Vue.directive('loading', {
        update(el, binding, vnode) {
          if(binding.value) {
            const div = document.createElement('div')
            div.innerText = '加载中...'
            div.setAttribute('id', 'loading')
            div.style.position = 'fixed'
            div.style.left = 0
            div.style.top = 0
            div.style.width = '100%'
            div.style.height= '100%'
            div.style.display = 'flex'
            div.style.justifyContent = 'center'
            div.style.alignItems = 'center'
            div.style.color = 'white'
            div.style.background = 'rgba(0, 0, 0, .7)'
            document.body.append(div)
          } else {
            document.body.removeChild(document.getElementById('loading'))
          }
        }
      })
      var vm = new Vue({
        el: '#root',
        data(){
          return {
            data:'asd',
            isLoading: false,
            message: '123123'
          }
        },
        created(){
          this.$on('my_events', val => {
            this.message = '-----'
          })
        },
        methods:{
          handleClick(){
            this.$emit('my_events')
          },
          update(){
            this.isLoading = true
            setTimeout(()=>{
              this.isLoading = false
            }, 1000)
          }
        }
      })
    </script>
    </body>
    </html>

     

  • 相关阅读:
    WCF进阶01 服务配置
    资源学习备忘 04
    .NET IoC主流框架 01:Castle Windsor Registering components onebyone
    IIS URL重写模块和ASP.NET路由组件比较
    资源学习备忘 03
    开源组件DockPanel Suite使用
    Dockable Window开源组件分享
    WCF进阶02 服务承载
    Prometheus 初探和配置(安装测试)
    TF31003错误的解决办法
  • 原文地址:https://www.cnblogs.com/jxjl/p/14300077.html
Copyright © 2020-2023  润新知