随笔分类 -  JavaScript

JavaScript的常用方法
摘要:1、创建 websocket.js 文件 // 定义 websocket export default { ws: {}, setWs: function(newWs) { this.ws = newWs }, } 2、在main.js 中引入 import wsk from './utils/we 阅读全文
posted @ 2022-03-14 14:13 yw3692582 阅读(1910) 评论(0) 推荐(0)
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content 阅读全文
posted @ 2022-01-12 14:20 yw3692582 阅读(41) 评论(0) 推荐(0)
摘要:语法:navigator.sendBeacon(url, data); 例子(写在mounted中): window.addEventListener("beforeunload", (e) => { window.navigator.sendBeacon(url, '测试发送的数据'); });参 阅读全文
posted @ 2021-08-24 19:51 yw3692582 阅读(217) 评论(0) 推荐(0)
摘要:// 语音播放 const synth = window.speechSynthesis const message = new SpeechSynthesisUtterance() function voice_playback(text) { message.text = text messag 阅读全文
posted @ 2021-08-07 18:00 yw3692582 阅读(207) 评论(0) 推荐(0)
摘要:/***** 主要需要一个变量(distinguish )来判断是哪种状态*****/ // 单击 once_click(item) { this.distinguish = true setTimeout(() => { if (this.distinguish) { // 处理单击事件的代码块 阅读全文
posted @ 2021-08-06 17:18 yw3692582 阅读(396) 评论(0) 推荐(0)
摘要:// 文件结构如下, 父容器高度固定,内容超出时出现滚动条,现在需要获取滚动条的位置 <div id="center" style="height: 500px;overflow-y: auto;"> <div></div> </div> script: var center_scrollTop = 阅读全文
posted @ 2021-08-06 13:53 yw3692582 阅读(2961) 评论(0) 推荐(0)
摘要:// 升序function compare(property) { return function (a, b) { let value1 = a[property]; let value2 = b[property]; return value1 - value2; };} // 降序functi 阅读全文
posted @ 2021-08-03 09:06 yw3692582 阅读(257) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2021-07-30 15:14 yw3692582 阅读(2549) 评论(0) 推荐(0)
摘要:let blob = new Blob([res], { type:'image/svg+xml', }) let fileURL = URL.createObjectURL(blob) console.log(fileURL) ps: type要为image/svg+xml, 而不是text/xm 阅读全文
posted @ 2021-06-29 11:13 yw3692582 阅读(1137) 评论(0) 推荐(0)
摘要:// 迭代器 Iteration() { /** * 适用场景: * 1、forEach: 适用用对数组进行操作,参考for循环 * 2、every:适用于对数组所有元素进行同一个判断,返回布尔值 * 3、some:适用于判断某个元素是否符合函数,返回布尔值 * 4、reduce:适用于对数组元素进 阅读全文
posted @ 2021-05-11 09:35 yw3692582 阅读(160) 评论(0) 推荐(0)
摘要:formatNode(node) { // 获取websocket发送的msg信息,写了一个递归,前提是要在调用formatNode函数传入的参数控制好 if (node.key != '值') { // 在sendMsg的头部添加,这样是为了后面转成字符串 this.sendMsg.unshift 阅读全文
posted @ 2021-04-28 09:33 yw3692582 阅读(57) 评论(0) 推荐(0)
摘要:let arr = [1, [1, 2], [2, , [3, 4, 5], 3,{'user_name':'张三','password':'admin'}], 4]; let newArr = []; function ddd(data) { data.forEach((item) => { if 阅读全文
posted @ 2021-04-23 15:40 yw3692582 阅读(461) 评论(0) 推荐(0)
摘要:// 简单粗暴,适用于简单的一些判断 let obj = { 1:'1', 2:'2', 3:'3' } return obj[a] 阅读全文
posted @ 2021-04-23 14:09 yw3692582 阅读(249) 评论(0) 推荐(0)
摘要:let blob = e.data; let url = window.URL.createObjectURL(blob) console.log(url) 阅读全文
posted @ 2021-04-14 15:04 yw3692582 阅读(226) 评论(0) 推荐(0)
摘要:在main.js中或者单独引入(这里是直接写在了main.js中) import axios from 'axios' // 首先引入 Vue.prototype.$ajax = axios // 然后挂载到vue上 // axios请求拦截器 axios.interceptors.request. 阅读全文
posted @ 2021-04-12 15:20 yw3692582 阅读(168) 评论(0) 推荐(0)
摘要:// 防止按钮抖动,思路:获取到本次和上次点击的时间戳,相减小于1000毫秒则return,阻止继续操作 if (new Date().getTime() - this.newTimeStamp < 1000) { return this.$message({ type: 'warning', me 阅读全文
posted @ 2021-03-31 09:58 yw3692582 阅读(466) 评论(0) 推荐(0)
摘要:1 getTokenTest() { //传统js方式获取url参数 2 let url = window.location.search 3 let token; 4 let loca_token = localStorage.getItem('token') 5 if (url) { 6 if 阅读全文
posted @ 2020-10-16 22:03 yw3692582 阅读(485) 评论(0) 推荐(0)
摘要:1 let obj1 = { 2 a:1, 3 b:2, 4 c:3 5 } 6 let obj2 = { 7 a:0, 8 b:0, 9 c:0 10 } 11 // 两个对象的字段完全相同时采用下面两种方式 12 obj2 = Object.assign(obj1) 13 obj2 = obj1 阅读全文
posted @ 2020-10-14 17:02 yw3692582 阅读(5067) 评论(0) 推荐(0)
摘要:1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <!-- 这几种数据格式都可以用for循环来遍历,for...of也都可以遍历绝大多数的数据结构 - 阅读全文
posted @ 2020-09-22 11:18 yw3692582 阅读(5848) 评论(0) 推荐(0)
摘要:1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <script type="text/javascript"> 9 let arr = [1,2,3 阅读全文
posted @ 2020-09-22 09:36 yw3692582 阅读(658) 评论(0) 推荐(0)