做项目中遇到了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'

    }

}

 

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-12-05
  • 2021-08-27
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-16
  • 2021-12-05
  • 2021-12-15
  • 2021-08-12
  • 2021-11-29
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案