您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

vue2.0动态组件与render使用说明

2025/10/30 6:38:58发布23次查看
这次给大家带来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>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
vue.js路由失效无法使用
怎样操作vue函数调用顺序
以上就是vue2.0动态组件与render使用说明的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product