vue中data的两种写法

//1、对象式
data: {
    ...
}

//2、函数式
data: function() {
    return{
        ...
    }
}
//----或者----//
data() {
    return{
        ...
    }
}
/*
对于函数式:
  1.写组件必须用函数式
  2.这里的function不能用【() => {}】[ 箭头函数 ] 代替,
    因为 箭头函数 没有自己的【this】,会往上一层找对象
    即: 
    function => this => vue对象
    ()=>{}   => this => 上一级对象
*/

 

posted @ 2022-02-25 00:56  六六_RAKU  阅读(562)  评论(0)    收藏  举报