let currentInstance = null // 缓存当前的vue实例
let isMounting = false // 初始化挂载 or 更新
let callIndex = 0 // 每个state的唯一标记id
function ensureCurrentInstance() {
if (!currentInstance) {
throw new Error(
`invalid hooks call: hooks can only be called in a function passed to withHooks.`
)
console.log(1);
new Promise(function (resolve, reject){
reject(true);
window.setTimeout(function (){
resolve(false);
}, 0);
}).then(function(){
console.log(2);
}, function(){
if (!("a" in window)) {
var a = 1;
}
console.log(a); // undefined
变量提升,在代码顶部申明
var a = undefined
,"a" in window
会返回true,if语句不会执行。
最近前端圈闹的沸沸扬扬的快排算法,由于对算法不熟悉,先借鉴高程作者的方案在这里。
function swap(items, firstIndex, secondIndex) {
var temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
}
function partition(items, left, right) {
function minNumbers() {
let len = Math.floor(Math.random() * 10 + 3);
let digit = Math.random().toString().slice(len);
console.log('给出的数字:', digit)
let arr = digit.split('');
let sort = arr.sort(function (a, b) {
return a - b;
});
// 1
function cloneObject(obj, parent) {
if (typeof obj !== 'object') {
return null;
}
const o = obj instanceof Array ? [] : {};
for (let key in obj) {
function countString(str) {
const arr = str.split('');
let n = 1;
let result = '';
for (let i = 0; i < arr.length; i++) {
if (arr[i + 1] === arr[i]) {
n++;
}
else {
(function(){
const t = window.performance && performance.timing;
if (!t) {
return;
}
const loadTime = (t.loadEventEnd - t.navigationStart) / 1000;
alert(`This page loaded in ${loadTime} seconds`);
}())
直接打开异步请求到的链接会被浏览器拦截。
可以使用如下解决方案:
async applyForAuth(row) {
const win = window.open('about:blank', '_blank');
const r = await getAuth(row.shopId);
if (r.code === '8001') {
win.location.href = r.data;
}
npm install npm@latest -g(可以更新npm至最新版本)
npm install webpack@latest -S 升级vue的版本
npm install vue-template-compiler@latest -S 升级compiler的版本
NewerOlder