美文网首页我爱编程
js对象与vue模块化思想

js对象与vue模块化思想

作者: 南京1865 | 来源:发表于2018-06-06 23:39 被阅读0次
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}//匿名函数
{a(){return {k:1}},b=1}

上述几种写法用法可能不太一样,但功能上基本一致

在.vue文件中,经常会看到这几个函数

export defalut {
created(){
},
mounted(){
},
methods:{
},
computed:{
}
}

对照图一的对象的集中写法,就很好理解其中的语法格式了
再如methodscomputed

methods:{
  name(){
    return xxx;
  }
},
computed:{
  name:function(){
    return xxx;
  }
}
//等价于
methods:{
  name:function(){
    return xxx;
  }
},
computed:{
  name(){
    return xxx;
  }
}

vue中.vue和.js文件中大量的使用了模块化的思想,基本上都是export一个{}的格式,里面最基础语法和js对象的语法是基本一致的

相关文章

网友评论

    本文标题:js对象与vue模块化思想

    本文链接:https://www.haomeiwen.com/subject/yvzisftx.html