前端常用 api(前端常用技术栈)
1.Vue变更数组 vm.$set
let array=[]; vm.$set(array,0,'newVal') //结果 ['newVal']; 复制代码
2.JSON.parse()
将得到的json数据转化为对象:
const json = '{"result":true, "count":42}'; const obj = JSON.parse(json); console.log(obj.count); // expected output: 42 复制代码
3.JSON.stringify()
将对象转化为字符串
console.log(JSON.stringify({ x: 5, y: 6 })); // expected output: "{"x":5,"y":6}" 复制代码
4.Object.assign(target, source)实现对象合并
const target = { a: 1, b: 2 }; const source = { b: 4, c: 5 }; const returnedTarget = Object.assign(target, source); console.log(target); // expected output: Object { a: 1, b: 4, c: 5 } 复制代码
重复的 key 以后面的结果 value 为准,该方法是浅拷贝
5. Date()时间函数
var d = new Date() // Wed Oct 27 2021 08:45:50 GMT+0800 (中国标准时间) d.getFullYear(); // 2021 d.getMonth()+1; // 12 d.getHours(); // 17 d.getMinutes(); // 12 d.getSeconds(); // 22 (new Date()).valueOf() // 1638436486394 new Date(1472048779952) // Wed Aug 24 2016 22:26:19 GMT+0800 (中国标准时间) 复制代码
6.splice方法
array.splice(index,howmany,item1,.....,itemX) 复制代码
index
从何处开始删除/新增
howmany
删除几个元素
item…
新增元素
7.this.$refs.RefName_.resetFields() 重置表单
重置引用为 addFormRef
的表单
this.$refs.addFormRef.resetFields()
作者:每天要买一个苹果
链接:https://juejin.cn/post/7037032219713470472
伪原创工具 SEO网站优化 https://www.237it.com/