一、模板渲染

<div id="J_render_app">
  <ul v-if="items.length">
    <li v-for="item in items">{{ item.name }}</li>
  </ul>
  <p v-else>No items found.</p>
</div>
var vrrapp = new Vue({
  el:"#J_render_app",
  data:{
    items:[
      { name: "vuejs" },
      { name: "angularjs" },
      { name: "reactjs" }
    ]
  }
})

二、组件模板渲染

<div id="J_render_app">
  <ul v-if="items.length">
    <my-li v-for="item in items" :tolearn="item"></my-li>
  </ul>
  <p v-else>No items found.</p>
</div>
Vue.component('my-li',{
  props:["tolearn"],
  template:'<li>{{ tolearn.name }}</li>'
})
var vrrapp = new Vue({
  el:"#J_render_app",
  data:{
    items:[
      { name: "vuejs" },
      { name: "angularjs" },
      { name: "reactjs" }
    ]
  }
})

三、render函数渲染

改变真实的DOM状态远比改变一个JavaScript对象的花销要大得多,这就是react和vue在性能方面的一大优势,下面简单介绍虚拟dom。
createElement告诉Vue页面上需要渲染什么样的节点,及其子节点。这些节点是虚拟节点,所有虚拟节点形成虚拟dom。

1、例子

<div id="J_render_app">
  <my-condition></my-condition>
</div>
Vue.component('my-condition',{
  data:function(){
    return {
      items:[
        {name:"vuejs"},
        {name:"angularjs"},
        {name:"reactjs"}
      ]
    }
  },
  render: function (createElement) {
    if (this.items.length) {
      return createElement('ul', this.items.map(function (item) {
        return createElement('li', item.name)
      }))
    } else {
      return createElement('p', 'No items found.')
    }
  }
})
var vrrapp = new Vue({
  el:"#J_render_app"
})

2、例子

<div id="J_render_app">
  <anchored-heading :level="2">Hello world!</anchored-heading>
</div>

var getChildrenTextContent = function (children) {
  return children.map(function (node) {
    return node.children ? getChildrenTextContent(node.children) : node.text
  }).join('')
}
Vue.component('anchored-heading', {
  render: function (createElement) {
    // create kebabCase id
    var headingId = getChildrenTextContent(this.$slots.default)
      .toLowerCase()
      .replace(/\W+/g, '-')
      .replace(/(^\-|\-$)/g, '')
    return createElement(
      'h' + this.level,
      [
        createElement('a', {
          attrs: {
            name: headingId,
            href: '#' + headingId
          }
        }, this.$slots.default)
      ]
    )
  },
  props: {
    level: {
      type: Number,
      required: true
    }
  }
})
var vrrapp = new Vue({
  el:"#J_render_app"
})

四、jsx渲染
vue推荐大部分情况下用模板渲染页面,但有时候也需要用render函数。为了更接近模板语法,可以在vue中使用jsx。

vue中的页面渲染方案的更多相关文章

  1. Web开发中,页面渲染方案

    转载自:http://www.jianshu.com/p/d1d29e97f6b8 (在该文章中看到一段感兴趣的文字,转载过来) 在Web开发中,有两种主流的页面渲染方案: 服务器端渲染,通过页面渲染 ...

  2. vue中在页面渲染完之后获取元素(否则动态渲染的元素获取不到)

    两种方法: 方法一: 使用$nextTick,在异步获得数据之后再获取元素: 方法二: 在then之后再获取该元素: 问题2:vue中监听改变数组的方法: let idx =; this.listIn ...

  3. 理解Vue中的Render渲染函数

    理解Vue中的Render渲染函数 VUE一般使用template来创建HTML,然后在有的时候,我们需要使用javascript来创建html,这时候我们需要使用render函数.比如如下我想要实现 ...

  4. vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改

    vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改.vue <div class="commonHeader" v-bind:class=" ...

  5. 3-7 Vue中的列表渲染

     举个案例:循环data中的list的值在div中,并显示相应的index值. 关于数组的循环: //显示效果如下图: //一般的列表渲染最好带一个key值,要把key值设置为唯一值的话,可以选择in ...

  6. 3-6 Vue中的条件渲染

    本次案例讲解:v-if,v-show,v-else,v-else-if和key值的相关用法!!! v-if指令: //通过一个(v-if)指令 ,可以结合js表达式的返回值,决定一个标签是否在页面上展 ...

  7. vue中嵌套页面 iframe 标签

    vue中嵌套iframe,将要嵌套的文件放在static下面: <iframe src="../../../static/bear.html" width="300 ...

  8. vue中嵌套页面(iframe)

    vue中嵌套iframe,将要嵌套的文件放在static下面.(要将打包文件整体放在statici里,我的文件名是canvas) src可以使用相对路径,也可使用服务器根路径http:localhos ...

  9. vue中判断页面滚动开始和结束

    参考链接:https://www.jianshu.com/p/adad39705ced    和  https://blog.csdn.net/weixin_44309374/article/deta ...

随机推荐

  1. LeetCode(96): 不同的二叉搜索树

    Medium! 题目描述: 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 3 输出: 5 解释: 给定 n = 3, 一共有 5 种不同结构的二叉搜索树: ...

  2. BrupSuite渗透测试笔记(十)

    一.Brup Repeater通常结合Proxy(历史记录),Scanner(扫描记录).Target(站点地图)等,通过其他工具上的右键执行[Send to Repeater],之后跳转到Repea ...

  3. poj3164 最小树形图板子题

    /* 思路很简单,也不知道哪里错了TAT */ /* N个点通过笛卡尔坐标表示 根节点是1,求最小树形图 */ #include<iostream> #include<cstdio& ...

  4. Python之argv简明详解

    今日看到argv 度娘查找一番,基本都是转载的同一篇文章,总体字数不少但看了之后感觉还是稀里糊涂,自己尝试了一番简单总结如下 当我们需要在命令行执行脚本并需要在执行脚本的同时传入参数给脚本使用,那我们 ...

  5. Springboot+MyBatis+JPA集成

      1.前言 Springboot最近可谓是非常的火,本人也在项目中尝到了甜头.之前一直使用Springboot+JPA,用了一段时间发现JPA不是太灵活,也有可能是我不精通JPA,总之为了多学学Sp ...

  6. centos/redhat破解账号密码

    说明:1.个人觉得centos系统和redhat系统差不多,界面都差不多一样. 2.下面方法用于开机root密码忘了,其他人篡改root密码等等 下面是破解账号密码(图解) 之后要等久点 效果: 方法 ...

  7. https请求抛出异常

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;// SecurityProtocolType.Tls1.2;

  8. STL用法大全

    1.    概述 泛型编程思想最早缘于A.Stepanov提出的部分算法可独立于数据结构的论断.20世纪90年代初A.Stepanov和Meng Lee根据泛型编程的理论用C++共同编写了STL.但直 ...

  9. MyBatis配置:在控制台打印SQL语句

    1.在spring-mybatis.xml中配置语句 注意:value=”classpath:mybatis-config.xml”这个文件如果之前没有,是需要新建的  2.新建mybatis-con ...

  10. Greenplum和Postgresql的主键自增

    参考:https://blog.csdn.net/u011042248/article/details/49422305 1.第一种情况就是创建数据表的时候创建主键自增,由于业务需要自己的数据表已经创 ...