在项目中使用iview的table控件时,遇到的问题:
1.表格如何显示图片(居中):
{
title: '户籍照片',
type: 'photoUrl',
align: 'center',
render: (h, params) => {
return h("div",{
style: { height: "100px", margin: "10px",overflow:'hidden',position:'relative' }
} ,
[h("img", {
attrs: { src: params.row.photoUrl },
style: {maxWidth:'100%',maxHeight:'100%',verticalAlign:'middle',position:'absolute',top:'50%',left:'50%',transform:'translate(-50%,-50%)' }
}
)]
);
}
}
2.如何根据值显示相应文本内容:
{
title: '性别',
key: 'gender',
align: 'center',
render:(h, params) => {
let gender = params.row.gender
if(gender == 1){
gender = '男'
}else if(gender == 2){
gender = '女'
}
return h('span',gender)
}
}
3.对应显示内容:
{
title: '操作',
key: 'operate3',
align: 'center',
render: (h, params) => {
return h('div', [
params.row.pkUserID == 'SUPERADMIN'?h('Button', {
props: {
type: 'primary',
// size: 'small'
},
style: {
margin:'20px 15px 20px 0px'
},
on: {
click: () => {
this.initEditPsw(params.row)
}
}
}, '修改密码'):
h('Button', {
props: {
type: 'primary',
// size: 'small'
},
style: {
margin:'20px 15px 20px 0px'
},
on: {
click: () => {
this.userEdit(params.row)
}
}
}, '修改'),
params.row.pkUserID == 'SUPERADMIN'?'':h('Button', {
props: {
type: 'primary',
// size: 'small'
},
on: {
click: () => {
this.delete('user',params.row)
}
}
}, '删除')
]);
}
}
或者
{
title:"操作",
key:"actor",
align:'center',
render: (h, params) => {
if(this.giftCardsList[params.index].status === '进行中'){
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.$router.push({ path: '../marketing_manage/add_gift_card?gcid=' + this.giftCardsList[params.index].gcid});
}
}
}, '编辑'),
h('Button', {
props: {
type: 'error',
size: 'small'
},
on: {
click: () => {
this.popupIsShow = true;
this.gcid = this.giftCardsList[params.index].gcid;
}
}
}, '使失效')
]);
}else{
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
on: {
click: () => {
this.$router.push({ path: '../marketing_manage/gift_card_warehouse?gcid=' + this.giftCardsList[params.index].gcid});
}
}
}, '码库')
]);
}
}
}