|
|
|
@ -147,5 +147,161 @@ export default function App(){ |
|
|
|
|
</div> |
|
|
|
|
</> |
|
|
|
|
} |
|
|
|
|
// 宏任务 和 微任务 |
|
|
|
|
console.log(1) |
|
|
|
|
|
|
|
|
|
function a(){ |
|
|
|
|
console.log(2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
(function autoRun(){ |
|
|
|
|
return console.log(3) |
|
|
|
|
})() |
|
|
|
|
setTimeout(() => { |
|
|
|
|
console.log(4) |
|
|
|
|
}) |
|
|
|
|
function b(){ |
|
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
|
console.log(5) |
|
|
|
|
new Promise((res) => { |
|
|
|
|
console.log(6) |
|
|
|
|
res(7) |
|
|
|
|
}) |
|
|
|
|
resolve(8) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
reject(9) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
a() |
|
|
|
|
b().then( |
|
|
|
|
res => { |
|
|
|
|
console.log(res) |
|
|
|
|
}, |
|
|
|
|
e => { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this指向问题 |
|
|
|
|
class A{ |
|
|
|
|
constructor() { |
|
|
|
|
this.name = 'haha' |
|
|
|
|
} |
|
|
|
|
one(){ |
|
|
|
|
return () => { |
|
|
|
|
console.log(this.name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
two(){ |
|
|
|
|
return function (){ |
|
|
|
|
console.log(this?.name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const aClass = new A() |
|
|
|
|
const one = aClass.one() |
|
|
|
|
const two = aClass.two() |
|
|
|
|
one() |
|
|
|
|
two() |
|
|
|
|
// two.call(aClass) |
|
|
|
|
// 打印结果是什么 |
|
|
|
|
// 如何让输出都为name |
|
|
|
|
|
|
|
|
|
// 解构赋值 |
|
|
|
|
let num1 = 99, num2 = 98; |
|
|
|
|
const str1 = 'World', str2 = 'Hello'; |
|
|
|
|
[num1, num2] = [num2, num1]; |
|
|
|
|
// [str1, str2] = [str2, str1]; |
|
|
|
|
console.log(num1, num2); |
|
|
|
|
console.log(str1, str2); |
|
|
|
|
|
|
|
|
|
// 三点运算符 |
|
|
|
|
const list1 = [1,2,3,4,5]; |
|
|
|
|
const list2 = [6,7,8,9,10]; |
|
|
|
|
let list = []; |
|
|
|
|
// 合并list1和list2 |
|
|
|
|
// 方法1 list = [...list, ...list2] |
|
|
|
|
// 方法2 list = list1.concat(list2) |
|
|
|
|
// 排序list |
|
|
|
|
// list.sort((x,y)=> x - y) |
|
|
|
|
|
|
|
|
|
// 数组去重 |
|
|
|
|
let arrNum = [1,1,3,4,4,9,1,4,6,8] |
|
|
|
|
// console.log(Array.from(new Set(arrNum))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 基础数据类型和复杂数据类型 |
|
|
|
|
function autoRun(){ |
|
|
|
|
let name = 'Nier' |
|
|
|
|
let people = { |
|
|
|
|
age: 24, |
|
|
|
|
sex: 1, |
|
|
|
|
birthday: `991332` |
|
|
|
|
} |
|
|
|
|
function makeNewPeople(name, people){ |
|
|
|
|
people.name = name |
|
|
|
|
name = 'Anto' |
|
|
|
|
console.log(name, people) |
|
|
|
|
} |
|
|
|
|
console.log(name, people) |
|
|
|
|
makeNewPeople(name, people) |
|
|
|
|
console.log(name, people) |
|
|
|
|
} |
|
|
|
|
autoRun() |
|
|
|
|
|
|
|
|
|
// 拷贝 |
|
|
|
|
function autoRun2(){ |
|
|
|
|
const CP1 = { |
|
|
|
|
cpu: 'i9 13900k', |
|
|
|
|
mem: '32GB 7600MHz DDR5', |
|
|
|
|
videoCard: 'RTX 4090' |
|
|
|
|
} |
|
|
|
|
const CP2 = { |
|
|
|
|
cpu: 'i5 8250U', |
|
|
|
|
mem: '8GB 3200MHz DDR4', |
|
|
|
|
videoCard: 'GTX 1050 MaxQ' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 合并CP1和CP2 |
|
|
|
|
// const CP = {...CP1, ...CP2} |
|
|
|
|
const CPList = [CP1, CP2] |
|
|
|
|
// 如何修改CP1而不导致CPList变化 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 格式化数据 |
|
|
|
|
function autoRun3(){ |
|
|
|
|
const resd = [ |
|
|
|
|
{ id: 32, name: 'a', fatherId: 0 }, |
|
|
|
|
{ id: 16, name:'b', fatherId: 32 }, |
|
|
|
|
{ id: 8, name: 'c', fatherId: 4 }, |
|
|
|
|
{ id: 7, name: 'c', fatherId: 8 }, |
|
|
|
|
{ id: 6, name: 'c', fatherId: 4 }, |
|
|
|
|
{ id: 5, name: 'c', fatherId: 4 }, |
|
|
|
|
{ id: 4, name: 'c', fatherId: 1 }, |
|
|
|
|
{ id: 3, name: 'c', fatherId: 16 }, |
|
|
|
|
{ id: 2, name: 'c', fatherId: 5 }, |
|
|
|
|
{ id: 1, name: 'c', fatherId: 0 } |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
// 将resd转化为树结构 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sessionStorage和localStorage的区别,从页面A打开页面B sessionStorage会失效吗 |
|
|
|
|
function autoRun5(){ |
|
|
|
|
window.location.href = "http://www.baidu.com"; |
|
|
|
|
window.history.go(-1); |
|
|
|
|
window.open('page.html'); |
|
|
|
|
this.$router.push('/goods/add') |
|
|
|
|
// <router-link to="/goods/add">点击跳转</router-link> |
|
|
|
|
this.$router.replace({path:'/goods/add'}); |
|
|
|
|
this.$router.go(-1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|