• vuejs关于函数式组件的探究


    所以,在控制台里app1.exist 或app2.exist都可以控制是否显示字母.

    <!DOCTYPE html>
    <html lang='zh'>
    <head>
      <title>TEST</title> 
    </head>
    
    <body>
    
    
      <div id="app1">
        <non-func :c_exist="exist"></non-func>
      </div>
      <div id="app2">
        <is-func :c_exist="exist"></is-func>
      </div>
    
    
    <script src="https://cdn.staticfile.org/vue/2.1.6/vue.min.js"></script>
    <script>
    
    var render1 = function (h) {
      var children = []
      if (this.c_exist) {
        children.push('Non-functional component')
      }
      return h('div', {}, children)  
    }
    Vue.component('non-func',{
      render :render1,
      props:['c_exist'],
    })
    var app1 = new Vue({
      el   : '#app1',
      data : {
        exist:true,
      },
    })
    
    // functional component
    var render2 = function (h, ctx) {
      console.log(ctx)
      var children = []
      if (ctx.data.attrs.c_exist) {  
        children.push('functional component')
      }
      return h('div', {}, children)  
    }
    Vue.component('is-func',{
      functional: true,
      render :render2,
    })
    
    var app2 = new Vue({
      el   : '#app2',
      data : {
        exist:true,
      },
    })
    
    </script>
    
    
    </body>
    </html>
    

    这样也可以:

    var render2 = function (h, ctx) {
      console.log(ctx)
      var children = []
      if (ctx.props.c_exist) {  
        children.push('functional component')
      }
      return h('div', {}, children)  
    }
    Vue.component('is-func',{
      functional: true,
      render :render2,
      props:['c_exist'],
    })
    
    var app2 = new Vue({
      el   : '#app2',
      data : {
        exist:true,
      },
    })
    
  • 相关阅读:
    自我介绍
    oracle 几种分页
    for update nowait
    彻底卸载SQL 2005
    如何将 SQL SERVER 彻底卸载干净
    iBatis 到 MyBatis区别
    SqlMapConfig.xml配置文件详解
    mybatis简单应用(基于配置文件)
    ibatis学习笔记一:sqlMapConfig.xml文件配置详解
    Extjs 中的添加事件总结
  • 原文地址:https://www.cnblogs.com/xiangnan/p/6754545.html
Copyright © 2020-2023  润新知