function reactive(state) {//n return {//n squareUrl: state.squareUrl || '',//n }//n}//n//nasync function getUserInfo() {//n const token = localStorage.getItem(/'token/');//n//n try {//n const response = await axios.get('http://nn.nncoding.icu:8080/api/user/info', {//n headers: {//n token: token//n }//n });//n let str = response.data.data.headUrl;//n // 使用正则表达式提取URL//n let url = str.match(/(http[s]?:////[^/s]+)/g);//n state.squareUrl = url[0];//n } catch (error) {//n console.error(error);//n }//n}//n//nconst state = {};//nconst reactiveState = reactive(state);//ngetUserInfo();//n//n// 要让上述代码正常运行,需要满足以下条件://n1. 引入axios库//n2. 确保localStorage中有名为/'token/'的项,并且其值是有效的//n3. 确保在运行该代码的环境中,可以访问'http://nn.nncoding.icu:8080/api/user/info'接口//n//n// 该代码使用异步函数getUserInfo,在axios请求完成后更新state对象的squareUrl属性。//n// 这样,当调用getUserInfo函数时,会发送请求获取用户信息,并将得到的头像URL更新到reactiveState对象的squareUrl属性中。

JavaScript 获取用户头像 URL 并更新状态