var str = ` var a = 1; console.log(a) `; let userName = "Dean"; console.log( ` I'm ${userName } ` ) ; // I'm Dean
块级做用域:数组
{ let a = 1; var b = 2; } console.log(a) // a is not defined console.log(b) // 2
const定义的是常量
(const声明的变量,内存地址不能够改变,可是空间的值能够改)promise
let a = 1; a = 2; const b = 2; b = 3; // 报错: Assignment to constant variable (常量不能改变)
const { resName, resPosition, parkAreaNum, parkStationNum, resDesImg } = resProduct.data; Object.assign(vm, { resName, resPosition, parkAreaNum, parkStationNum, resDesImg });
传统的写法是: vm.resName = resProduct.data.resName异步
function sum(...m){ let total = 0; for(var i of m) { total += i; } console.log(`total: ${total}`) } sum(4,5,6,9);
数组code
const color = ["red", "yellow"]; const colorful = [...color, "green", "pink"]; console.log(colorful); //[red, yellow, green, pink]
对象对象
const alp = { fist: "a", second: "b" }; const alphabets = { ...alp, third: "c" }; console.log(alphabets); //{ "fist": "a", "second": "b", "third": "c"
function runAsync1() { var p = new Promise(function(resolve, reject) { //作一些异步操做 setTimeout(function() { console.log('异步任务1执行完成'); resolve('数据1'); }, 1000); }); return p; } function runAsync2() { var p = new Promise(function(resolve, reject) { //作一些异步操做 setTimeout(function() { console.log('异步任务2执行完成'); resolve('数据2'); }, 2000); }); return p; } function runAsync3() { var p = new Promise(function(resolve, reject) { //作一些异步操做 setTimeout(function() { console.log('异步任务3执行完成'); resolve('数据3'); }, 2000); }); return p; } runAsync1() .then(function(data) { console.log(data); return runAsync2(); }) .then(function(data) { console.log(data); return runAsync3(); }) .then(function(data) { console.log(data); });
import util from "../../js/util.js"; export default { name: 'home', data () {}, methods: {} }
(若有不足之处,请多指教)内存