JS對象的幾種寫法形式
const a={k:1};
example(){
return {k:1};
}
//以下幾種對象的寫法都是可以的
{a:a,b=1}
{a,b=1}//es6語法疼电,形如a:a這類屬性與變量同名的嚼锄,可以簡寫一個名字就可以了
{a:example,b=1}
{a:function(){return {k:1}},b=1}//匿名函數(shù)
{a(){return {k:1}},b=1}
上述幾種寫法用法可能不太一樣,但功能上基本一致
在.vue文件中蔽豺,經(jīng)常會看到這幾個函數(shù)
export defalut {
created(){
},
mounted(){
},
methods:{
},
computed:{
}
}
對照圖一的對象的集中寫法区丑,就很好理解其中的語法格式了
再如methods
和computed
methods:{
name(){
return xxx;
}
},
computed:{
name:function(){
return xxx;
}
}
//等價于
methods:{
name:function(){
return xxx;
}
},
computed:{
name(){
return xxx;
}
}
vue中.vue和.js文件中大量的使用了模塊化的思想,基本上都是export
一個{}的格式,里面最基礎(chǔ)語法和js對象的語法是基本一致的