1、当对象的key和value名称一致时,可以缩写成一个。
components:{
vTitle,
vButton
}
等同于:
components:{
vTitle:vTitle,
vButton,vButton
}
2、data(){}等同于data:function(){}
data(){
return{
name:'xxx'
}
}
等同于
data:function(){
return {name:'xxx'}
}
3、=>是箭头函数
render:h=>h(App)等同于:
render:function(h){
return h(App);
}
也等同于:
render:h=>{
return h(App);
}
4、在ES6语法中使用let和const命令来声明变量,代替了var。let和const的作用域是“块”,比如:
{
let a = 1;
var b = 2;
}
console.log(b);//2
console.log(a);//报错,a is not defined.
const和let的主要区别是,const用于声明常量,也就是声明后不能再修改。
5、Promise是一种异步方案,它有3种状态:pending(进行中)、Resolved(已完成)、Rejected(已失败)。示例:
const promise = new Promise((resolve,reject)=>{
setTimeout(()=>{
const random = Math.random();
if(random>0.5){
resolve(random);
}else{
reject(random);
}
},1000);
});
promise.then((value)=>{
console.log('success',value);
})catch((error)=>{
console.log('fail',error);
});
async/promise/await语法可查看:https://blog.csdn.net/u011649691/article/details/82591082
6、解构赋值:
https://blog.csdn.net/u011649691/article/details/82622478
7、import,export语法和含义:
export { name1, name2, …, nameN };
export { variable1 as name1, variable2 as name2, …, nameN };
export let name1, name2, …, nameN; // also var
export let name1 = …, name2 = …, …, nameN; // also var, const
export default expression;
export default function (…) { … } // also class, function*
export default function name1(…) { … } // also class, function*
export { name1 as default, … };
export * from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
import defaultMember from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import defaultMember, { member [ , [...] ] } from "module-name";
import defaultMember, * as name from "module-name";
import "module-name";
export用于对外输出本模块(一个文件可以理解为一个模块)变量的接口
import用于在一个模块中加载另一个含有export接口的模块。