vue2.0动态组件与render使用说明
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了vue2.0动态组件与render使用说明,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1929字,纯文字阅读大概需要3分钟。
内容图文
这次给大家带来vue2.0动态组件与render使用说明,vue2.0动态组件与render使用的注意事项有哪些,下面就是实战案例,一起来看一下。如下所示:
<template> <p class="hello"> <h1>{{ msg }}</h1> <h2>这里是Boor</h2> <component v-bind:my-data="items" v-bind:is="currentView"> <!-- 组件在 vm.currentview 变化时改变! --> </component> <a class="explain">直直</a> <button v-on:click="addData">点击</button> </p> </template> <script> //import $ from '@/assets/scripts/lib/zepto.min' //console.log($); //import Vue from 'vue' function isEmptyObject(e) { var t; for (t in e) return !1; return !0 } function objectLength(o) { var len = 0; for(var p in o) { len++; } return len; } let data ={ c_0:{c:1}, c_1:{c:2}, c_2:{c:3}, c_3:{c:4} }; let num = 0; //console.log(objectLength(data)); const MyComponent = { //template: '<h3 v-for="item in items">{{ item.c}}</h3>', props: ['myData'], data(){ return{ //items : myData } }, render: function (createElement) { debugger; let items = this.myData; //items = JSON.stringify(items); let num = objectLength(items); if (!isEmptyObject(items)) { debugger; return createElement('p', Array.apply(null, { length: num }).map(function (v,index) { return createElement('h3', items['c_'+index]['c'].toString()) })) } else { return createElement('h1', '没有数据!'); } } }; // 注册 //Vue.component('my-component', MyComponent); export default { name: 'bar', data () { return { msg: 'Bar', fuck: 'Hello', items: data, currentView: MyComponent } }, methods:{ addData : function(){ for(let p in data) { if(p == 'c_'+num) { data[p] = {'c': num }; } else { data['c'+num] = {'c': num }; } } num++; } } }; </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } </style>
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
vue.js路由失效无法使用
怎样操作vue函数调用顺序
以上就是vue2.0动态组件与render使用说明的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的vue2.0动态组件与render使用说明全部内容,希望文章能够帮你解决vue2.0动态组件与render使用说明所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。