做项目中遇到了data赋值的问题,总结了下常用的data赋值的数据类型。之前一直不确定是否能在data里写函数,实践证明data里也是可以对函数赋值的。
export default {

    name: 'test',

    data () {
        return {
             string: 'I'm string',

          number: 1,

          boolean: false,

          array: [],
 
          object: {},

          tryFun: function() { alert('just tryFun'); }
       }
    },

 created() {

       this.tryFunc();    //会弹出 'just tryFunc'

    }

}