vue中props的默認寫法


1.默認寫法

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;
      }
    }
  },

2.注意:
如果默認值得類型為數組或者對象,一定要在函數中返回這個默認值,而不是直接寫,否則報錯

正確:

 menu:{
     type:Array,
     default:function(){
         return []
     }
 }

錯誤:

menu:{
     type:Array,
     default:[]
 }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM