Loading

Vue常用代码操作

list删除元素

使用splice方法删除下标为index的元素

this.splice(index, 1);

list代码循环

使用foreach

res.forEach((item, key) => {
    console.log(item);
});

使用fori

for (let i = 0, len = list.length; i < len; i++) {
    console.log(list[i]);
}

list动态添加

this.lists.push({
	id:1,
	title:'abc'
})

vue获取当前路由信息

$route.path	//当前路由对象的路径,如'/vi
$route.query	//请求参数,如/foo?user=1获取到query.user = 1
$route.router	//所属路由器以及所属组件信息
$route.matched	//数组,包含当前匹配的路径中所包含的所有片段所对应的配置参数对象。
$route.name	//当前路径名字

vue跳转界面

this.$router.push('/home/first')
this.$router.push({path: '/home/first' })
this.$router.push({path: '/order/page1',query:{ id:'2'}});
this.$router.push({name: '/order/page2',params:{ id:'6'}});

string转int

parseInt('1')

删除对象中某个属性

this.$delete(this.form,'members')//删除form对象中的members属性

动态给对象添加属性

this.$set(this.pushJson, 'alias', []);//给pushJson对象添加属性alias并赋值为空数组
this.$set(this.pushJson, 'num', 1);//给pushJson对象添加属性num并赋值为1

时间转换

格林威治时间格式GMT --> 普通时间格式:

function GMTToStr(time){
    var date = new Date(time)
    var Str=date.getFullYear() + '-' +
    (date.getMonth() + 1) + '-' + 
    date.getDate() + ' ' + 
    date.getHours() + ':' + 
    date.getMinutes() + ':' + 
    date.getSeconds()
    return Str
}

普通时间格式 --> GMT:

function StrToGMT(time){
    var GMT = new Date(time)
    return GMT
}

RSA加密

npm i jsencrypt
import JsEncrypt from 'jsencrypt/bin/jsencrypt';
let jse = new JsEncrypt();
jse.setPublicKey(pubKey); // 加入rsa public key
let password = jse.encrypt(password); // 将password加密
posted @ 2021-01-06 13:46  冲锋的麦克  阅读(101)  评论(0编辑  收藏  举报