一、模板渲染

<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. 【splunk】按时间统计并找到异常值

    场景: 有长时间对多个端口访问的日志数据,每天对端口的访问量是稳定的.如果某一天对某个端口的访问量突然增加表示可能出现了问题.现在要通过splunk找到异常值. 思路: 统计每个端口每天的访问量.统计 ...

  2. Web Penetration Testing w3af fierce

    1.启动wsaf工具,设置载入插件(攻击模型的插件),可以设置默认的攻击模型,也可以添加自己的plug. 2.在侦查的时候渗透邮箱需要知道,云行邮箱服务的托管服务器是什么类型,在之前的博客中我已近两提 ...

  3. java实现 排序算法(鸡尾酒排序&选择排序&插入排序&二分插入排序)

    1.鸡尾酒排序算法 源程序代码: package com.SuanFa; public class Cocktial {    public static void main(String[] arg ...

  4. bzoj1195 神奇的ac自动机+状态压缩dp

    /* 难的不是ac自动机,是状态压缩dp 之前做了一两题类似题目,感觉理解的还不够透彻 */ #include<iostream> #include<cstdio> #incl ...

  5. Python集合(set)

    Python中的集合同数学中的集合概念类似,也是用于保存不重复的元素.他有可变集合(set),和不可变集合(frozenset);可变集合(set)是无序的可变的. 创建集合 直接使用{}创建 set ...

  6. 如何获取jar包的在执行机上面的路径

    背景: 最近在项目中遇到一个小问题, 几行代码就能解决了 String path = this.getClass().getProtectionDomain().getCodeSource().get ...

  7. axios简单使用

    介绍 我在使用vue的时候使用到了axios,vue 1.0的版本作者推荐使用vue-resource,到了vue 2.0作者建议使用axios,此篇文章只是我在使用axios时候做的笔记,我遇到的一 ...

  8. jquery.pjax 单页面, 无刷新打开页面.

    介绍: pushState+ajax=pjax 工作原理: 什么是pjax? 现在很多网站(facebook, twitter)都支持这样的一种浏览方式, 当你点击一个站内的链接的时候, 不是做页面跳 ...

  9. lojround6

    花团 线段树分治裸题 给出了结束时间跟离线没区别 「LibreOJ Round #6」花火 首先在第一次使用交换是显然的 然后统计逆序对暴力是n^2的(前缀和优化) 因为交换两个点改变的只有x< ...

  10. 【BZOJ2560】串珠子

    题解: 跟n个点有标号的无向连通图个数几乎一模一样 直接上代码了 代码: #include <bits/stdc++.h> using namespace std; #define ll ...