js使用小记

121 阅读1分钟

1.获取链接url中指定参数

使用window.url类;

new URL(location.href).searchParams.get('year')

// Returns 2008 for href = "http://localhost/search.php?year=2008".

// Or in two steps

const params = new URL(location.href).searchParams; const year = params.get('year');

2. 后端返过来图片是 MIME Code ,前端应该怎么解析显示在页面上

在返回mime code 字段里 加上 ‘data:iamge/jpeg;base64’即可

3.js 字符串数值相加

let  a = ’1‘, b = ’2‘

第一种常见写法:

let c =  Number(a) + Number(b)

第二种

let c = +a + +b  

上述两种写法效果是一样的

tips:+号应用单个值的时候,对数字是没有用的。后面跟的如果不是数字 会将其转化为数字