zoukankan      html  css  js  c++  java
  • vue 判断属性是否为object

    //递归对象
    var recursiveObject = Vue.extend({
      name: 'recursive-object',
      template:[
      '<ul>',
        '<li v-for="(key,val) in data">',
                '<div v-if="is_obj(val)">',
            '<span>{{ key }}</span>',
           '<recursive-object :data="val"></recursive-object>',
           '</div>',
           '<span v-if="!is_obj(val)">{{key}} - {{val}}</span>',
        '</li>',
      '</ul>'].join(''),
      props:{data:{}},
      methods:{
        is_obj:function(val){
          return Object.prototype.toString.call(val) === '[object Object]'
        }
      }
    })
    //注册个递归组件
    Vue.component('recursiveObject',recursiveObject)
    
    //go...
    new Vue({
      el:'#app',
      data:function(){
        return {
          data:{
            text:'yes',
            a0:{
              test1:'vace1',
              test2:'vace2'
            },
            a1:{
              asub1:{
              asubsub1:'hello1',
              asubsub2:'hellow'
             },
            asub2:{
              asubsub1:'hello4',
              asubsub2:'hello5',
              asubsub3:{
                asubsubsub1:'world',
                asubsubsub2:'world'
              }
            }
          }
          }
        }
      }
    })
  • 相关阅读:
    HTML和CSS 基本要点必看
    CSS
    六个选择器
    HTML初级课程 (自学可懂)
    this
    1.作用域链
    js if 语句
    js数据类型
    ifelse语句
    三元运算符
  • 原文地址:https://www.cnblogs.com/guozhe/p/7121647.html
Copyright © 2011-2022 走看看