美文网首页
2020-04-01 vue中props的默认写法

2020-04-01 vue中props的默认写法

作者: sll_ | 来源:发表于2020-04-01 10:54 被阅读0次

默认写法

props: {
    rowClick: {
      type: Function,
      default: function() {}
    },
    title: {
      type: String,
      default: "标题"
    },
    display: {
      type: String,
      default: "table" 
    },
    columnCount: {
      type: Number,
      default: 4
    },
    columns: {
      type: Array,
      default() {
        return [];
      }
    },
    showPage: {
      type: Boolean,
      default: true
    },
    api: {
      type: Object,
      default() {
        return {};
      }
    },
    parameter: {
      type: Object,
      default() {
        return {};
      }
    },
    defaultParameter: {
      type: Boolean,
      default() {
        return true;
      }
    }
  },

如果默认值得类型为数组或者对象,一定要在函数中返回这个默认值,而不是直接写,否则报错
正确:
 menu:{
     type:Array,
     default:function(){
         return []
     }
 }
错误
 menu:{
     type:Array,
     default:[]
 }

或者直接跟上面第一个代码一样,不管什么类型,都写在函数返回中。

相关文章

网友评论

      本文标题:2020-04-01 vue中props的默认写法

      本文链接:https://www.haomeiwen.com/subject/kfeouhtx.html