250 1 分钟

<script type="text/javascript"> var array = [1, 2, 1, 1, '1', '一']; // 构建带 array,array1 两个参数的函数 function uq(array) { // 将 array 数组转换成 set 对象,再使用 Array.from () 方法将 set 对象转换成数组 return Array.from(new Set(array)); } //...
3.2k 3 分钟

function submitLoginForm(e) { e = window.event || e; if(e.keyCode == 13) { login(); } } <!--more--> keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 = Shift_L keycode 17 = Control_L keycode 18 =...
1.6k 1 分钟

使用 <font style="color:#CC0000">Vue Material</font> 的 <font style="color:#CC0000">Dialog</font> 做了一个弹出框,弹出框内动态绑定了几个数据,页面效果一出来

2.5k 2 分钟

# 基本方法

var savaFile=function(data,filename)
{
    var save_link=document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
    save_link.href=data;
    save_link.download=filename;
    var event=document.createEvent('MouseEvents');
    event.initMouseEvent('click',true,false,window,0,0,0,0,0,false,false,false,false,0,null);
    save_link.dispatchEvent(event);
};
var download=function()
{
	const canvas = document.querySelector('canvas');
	var dataURL = canvas.toDataURL("image/png");
	saveFile(dataURL,'test.jpg');
}

217 1 分钟

引入 axios,并且已经挂到 vue 实例上面了。 this.$http.get('api/getNewsList').then((res)=&gt;{this.news=res.data}).catch((err)=&gt;{console.log(err)}) 使用的时候报出了上述错误 解决方法 //import VueResource from 'vue-resource' // Vue.use(VueResource); 老铁把这两个注释了就好了
10k 9 分钟

# axios

基于 promise 用于浏览器和 node.js 的 http 客户端

# 特点

  • 支持浏览器和 node.js
  • 支持 promise
  • 能拦截请求和响应
  • 能转换请求和响应数据
  • 能取消请求
  • 自动转换 JSON 数据
  • 浏览器端支持防止 CSRF (跨站请求伪造)
8.6k 8 分钟

本文主要介绍 24 中 es6 方法,这些方法都挺实用的,本本请记好,时不时翻出来看看。

# 1. 如何隐藏所有指定的元素

const hide = (el) => Array.from(el).forEach(e => (e.style.display = 'none'));
// 事例:隐藏页面上所有 `<img>` 元素?
hide(document.querySelectorAll('img'))

# 2. 如何检查元素是否具有指定的类?

页面 DOM 里的每个节点上都有一个 classList 对象,程序员可以使用里面的方法新增、删除、修改节点上的 CSS 类。使用 classList,程序员还可以用它来判断某个节点是否被赋予了某个 CSS 类。

const hasClass = (el, className) => el.classList.contains(className)
// 事例
hasClass(document.querySelector('p.special'), 'special') // true

# 3. 如何切换一个元素的类?

const toggleClass = (el, className) => el.classList.toggle(className)
// 事例 移除 p 具有类 `special` 的 special 类
toggleClass(document.querySelector('p.special'), 'special')