对象转数组
讲对象的key和value分开命名。
let data=[]
let user = {
name: "John",
age: 30,
isAdmin: true
};
for (let item in user ) {
let obj = {
value: user [item],
name: item
};
data.push(obj);
}
/**
结果
[{…}, {…}, {…}]
0: {value: 'John', name: 'name'}
1: {value: 30, name: 'age'}
2: {value: true, name: 'isAdmin
*/
在使用element时,将表单内容为空时添加 -
*记 在element中,暂时没有单项内容为空状态,需自行添加
<el-table-column
label="类型"
width="75" >
<template slot-scope="scope">{{scope.row.name?scope.row.name:'--'}}</template>
</el-table-column>
$route.query使用
*在路由组件中直接使用,获取内容即可。 ?? 与三元等类似
let query = this.$route.query;
this.queryData = {
userName: "", // 用户名
zombieUsers: query.zombieUsers ?? "", //是否僵尸用户
status: query.status ?? "", //用户状态
};
特殊字符规则校验
/[`~!@#$%^&() -+=<>?:"{}|,.\/;'\[]·~!@#¥%……&()——-+={}|《》?:“”【】、;‘’,。、]/
其他知识点:
文件导出
* 在获取需要下载的内容时,注意传递参数的类型
请求:
export function fileDownload(params) {
return request({
url: `/year=${params}`,
method: 'get',
responseType: "blob", //可以通过MDN查看
});
}
// res.data为后端返回的值
fileDownload(params).then((res) => {
console.log(res)
if (res.status === 200) {
const link = document.createElement('a')
let blob = new Blob([res.data], {
type: 'application/vnd.ms-excel',
})
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
link.download = '下载名称'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
问题一:父子组件传参,子组件接收不到。
有可能存在执行顺序,应先获取数据,在进行数据渲染
问题二:子组件接收到父组件参数无法修改。
原因:原型引用链断掉
方法;this.$set(数据来源,数据名称,挂载原型)