1.flex布局实现垂直置顶,靠右对齐

.container{
	display: flex;
	align-items: flex-start; 
	justify-content: flex-end;
}

2.align-content和align-self的区别

const square = function(x){
	return x * x;
}

const squareArrow = x => x *x;
const obj = {
	method: function(){
		console.log(this === obj);
	}
};
obj.method();
const promise = new Promoise((resolve, reject)=>{
	const success = true;
	if (success){
		resolve("succ")
	} else{
		reject("failed")
	}

})
promise.then(
(value)=>{console.log(value);}
(error)=>{console.log(error);}
)

链式调用

promise
.then((value)=>{
	console.log(value);
	return "doing next operation";
})
.then((nextValue)=>{

})
.catch((error)=>{
	console.log(error);
})

错误处理

promise
.then(()=>{

})
.catch((error)=>{

})

优势:

6.看一道promise代码输出题(涉及微任务和宏任务)

console.log("1");

setTimeout(()=>{
	console.log("2");
	Promise.resolve().then(()=>{
		console.log("3");
	})
}, 0);

Promose.resolve().then(()=>{
	console.log("4");
	setTimeout(()=>{
		console.log("5");
	}, 0)

})

console.log("6");
  1. 同步代码1,6
  2. 微任务Promise4
  3. 宏任务输出

7.写两道题,一道正则,一道时间戳转年月日

function timestampToYMD(timestamp){
	const date = new Date(timestamp);
	const year = date.getFUllYear();
	const month = (date.getMonth() + 1).toString().padStart(2, "0")
	const day = date.getDate().toString().padStart(2, "0");
	return "${year}-${month}-${day}";
}

8.封装一个通用的fetch请求

async function fectchReq(url, options={}){
	const method = options.method || "GET";
	const headers = {
	"Content-Type": "application/json",
	...options.headers
		}
	const config = {
		method,
		header
	}
	if (method === "POST" && options.body) {
		config.body = JSON.stringify(options.body);
	}
	try{
		const res = await fetch(url, config);
		if(!response.ok){
			throw new Error("HTTP error! status: ${res.status}");
		}
		return await response.json();
	}catch(error){
		throw error;
	}

}

9.说说es6的class和构造函数

function Person(name, age){
	this.name = name;
	
}

Person.prototype.sayHello = function(){
	console.log("Hello, my name is ${this.name}");
}

const person1 = new Person("Alice", 30);
person1.sayHello()
class Person {
	constructor(name, age){
		this.name = name;
		this.age = age;
	}
	sayHello(){
		console.log("Hello, my name is ${this.name}");
	}
}
const person1 = new Person("bob", 25);
person1.sayHello();

9.手写一个react手动计数组件

import React, {useState} from "react";

funtion Counter(){
	const [count, setCount] = useState(0);
	const increment =()=>{
		setCount(count + 1);
	}
	const decrement=()={
		setCount(count - 1);
	}

	return (
	<div>
	{count}
		<button onClick={increment}>+</button>
		<button onClick={decrement}>-</button>
	</div>
	)

}

export default Counter;

10.点击一个button,另一个button也计数怎么实现
11.实习中哪里用到了状态提升
状态提升是一种数据流管理技术,用于在组件中共享状态。当多个组件需要访问和修改同一个状态时,将状态提升到这些组件的最近共同父组件中,然后通过props将状态和用于修改状态的函数传递到需要他们的子组建中

import React, {useState} from "react";
import InputComponent from "./InputComponent";

function Form(){
	const [inputValue, setInputValue] = useState("");

	const handleInputChange = (e) =>{
		setInputValue(e.target.value);
	}
	return (
	...
	)

}

function InputComponent({value, onChange}){
	return <input type='text' value={value} onChange={onChange}/>;
}

12.手写一个自定义hooks
自定义hooks是一种在多个组件之间或者不同项目中共享逻辑。
useFormInput自定义Hook

import {useState} from "react";

function useFormInput(initialValue){
	const [value, setValue] = useState(initialValue);
	const handleChange = (e) => {
		setValue(e.target.value);
	}
	const reset = () => {
		setValue(initialValue);
	}
	return {
		value,
		onChange: handleChange,
		reset
	}

}
export default useFormInput

import React from "react";
import useFormInput from "./useFormInput";

function FormComponent(){
	const name = useFormInput();
	const handleSubmit = (event) => {
		event.preventDefault();
		alert(`a name was submitted: ${name.value}`);
		name.reset()
	}
	return (
		<form onSubmit={handleSubmit}>
			<label>
				<input type="text">
			</label>
			
		</form>
	)
}

13.函数式组件怎么暴露自己的数据和方法给父组件使用