tiny-vue_version0/examples/sites/demos/pc/app/grid/dynamically-columns/dynamic-slot.vue

98 lines
2.3 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<div class="button-box">
<tiny-button @click="change">改变列插槽</tiny-button>
</div>
<tiny-grid :data="tableData">
<tiny-grid-column type="index" width="60"></tiny-grid-column>
<tiny-grid-column v-for="col in cols" :key="col.field" :field="col.field" :title="col.title">
<template v-if="col.header" #header>
<div>{{ col.header.value }}</div>
</template>
<template v-if="col.default" #default>
<div>{{ col.default.value }}</div>
</template>
</tiny-grid-column>
<tiny-grid-column field="address" title="地址"></tiny-grid-column>
<tiny-grid-column field="introduction" title="公司简介" show-overflow></tiny-grid-column>
</tiny-grid>
</div>
</template>
<script>
import { Grid, GridColumn, Button } from '@opentiny/vue'
let times = 1
const createNewCols = () => [
{
field: 'name',
title: '名称',
header: {
value: `header-${++times}`
}
},
{
field: 'area',
title: '所属区域',
default: {
value: `col-${times}`
}
}
]
export default {
components: {
TinyGrid: Grid,
TinyGridColumn: GridColumn,
TinyButton: Button
},
methods: {
change() {
this.cols = createNewCols()
}
},
data() {
return {
cols: [
{
field: 'name',
title: '名称',
header: {
value: `header-${times}`
}
},
{
field: 'area',
title: '所属区域',
default: {
value: `col-${times}`
}
}
],
tableData: [
{
id: '1',
name: 'GFD科技YX公司',
area: '华东区',
address: '福州',
introduction: '公司技术和研发实力雄厚是国家863项目的参与者并被政府认定为“高新技术企业”。'
},
{
id: '2',
name: 'WWWW科技YX公司',
area: '华南区',
address: '深圳福田区',
introduction: '公司技术和研发实力雄厚是国家863项目的参与者并被政府认定为“高新技术企业”。'
}
]
}
}
}
</script>
<style scoped>
.button-box {
margin-bottom: 20px;
}
</style>