基于vue2.0動(dòng)態(tài)組件及render詳解
如下所示:
<template> <div class="hello"> <h1>{{ msg }}</h1> <h2>這里是Boor</h2> <component v-bind:my-data="items" v-bind:is="currentView"> <!-- 組件在 vm.currentview 變化時(shí)改變! --> </component> <a class="explain">直直</a> <button v-on:click="addData">點(diǎn)擊</button> </div> </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('div', Array.apply(null, { length: num }).map(function (v,index) { return createElement('h3', items['c_'+index]['c'].toString()) })) } else { return createElement('h1', '沒有數(shù)據(jù)!'); } } }; // 注冊(cè) //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>
以上這篇基于vue2.0動(dòng)態(tài)組件及render詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3.x如何設(shè)置瀏覽器動(dòng)態(tài)Title方法
這篇文章主要介紹了Vue3.x如何設(shè)置瀏覽器動(dòng)態(tài)Title方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03Mint UI組件庫CheckList使用及踩坑總結(jié)
這篇文章主要介紹了Mint UI組件庫CheckList使用及踩坑總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12在vue中使用rules對(duì)表單字段進(jìn)行驗(yàn)證方式
這篇文章主要介紹了在vue中使用rules對(duì)表單字段進(jìn)行驗(yàn)證方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新)
這篇文章主要介紹了VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2020-04-04詳解在vue中如何實(shí)現(xiàn)屏幕錄制與直播推流功能
屏幕錄制和直播推流是現(xiàn)代Web應(yīng)用中常用的功能,Vue作為一種流行的JavaScript框架,提供了一些工具和庫,可以方便地實(shí)現(xiàn)屏幕錄制和直播推流功能,本文將介紹如何在Vue中進(jìn)行屏幕錄制和直播推流,需要的朋友可以參考下2024-01-01Electron+Vue3+Vite搭建桌面應(yīng)用的示例代碼
本文主要介紹了Electron+Vue3+Vite搭建桌面應(yīng)用的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07