vuejs2 - quasar框架中的Q-Table,状态对象数据表不显示
问题描述
quasar框架中的Q-Table,状态对象数据表不显示,我试过这个但不起作用,
任何人,请帮助我。很抱歉这个主题还是新手
<script>
import { mapGetters } from 'vuex'
export default {
computed: {
...mapGetters('dataku', ['dataku'])
},
data () {
return {
columns: [
{ name: 'id', label: 'ID', field: 'id', value: 'id' },
{
name: 'name',
required: true,
label: 'Dessert (100g serving)',
align: 'left',
field: row => row.name,
format: val => `${val}`,
sortable: true
},
{ name: 'calories', label: 'Calories', field: 'calories', value: 'calories' },
{ name: 'fat', label: 'Fat (g)', field: 'fat', value: 'fat'},
{ name: 'carbs', label: 'Carbs (g)', value: 'crabs', field: 'carbs' },
{ name: 'protein', label: 'Protein (g)', value: 'protein', field: 'protein' },
{ name: 'action', label: 'Action', value: 'action', field: 'action', align: 'center' }
],
}
}
}
</script>
//这是vuex
const state = {
dataku: {
'iD1' : {
name: 'Baghoy',
calories: 19,
fat: 6.0,
carbs: 24,
protein: 4.0
},
'iD2' : {
name: 'Ice cream sandwich',
calories: 27,
fat: 9.0,
carbs: 37,
protein: 4.3
},
'iD3' : {
name: 'Eclair',
calories: 22,
fat: 16.0,
carbs: 23,
protein: 6.0
}
}
}
const mutation = {
}
const action = {
}
const getters = {
dataku: (state) => {
return state.dataku
}
}
export default {
namespaced: true,
state,
mutation,
action,
getters
}
<template>
<div class="q-pa-md">
<q-table
title="Treats"
:data="dataku"
:columns="columns"
row-key="name"
key="key"
:id="key"
>
<template v-slot:body-cell-action = "props">
<q-td :props="props">
<div>
<q-td key="action" :props="props">
<div class="right">
<q-btn flat scratch align="right" class="center" color="primary" icon="edit" @click="editItem(dataku)"/>
<q-btn flat scratch align="right" color="primary" icon="delete" @click="deletItem(dataku)"/>
</div>
</q-td>
</div>
</q-td>
</template>
</q-table>
</div>
</template>
解决方案
您需要更改数据结构。试试这个代码。
Vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
dataku: [
{
id: 'iD1',
name: 'Baghoy',
calories: 19,
fat: 6.0,
carbs: 24,
protein: 4.0
},
{
id: 'iD2',
name: 'Ice cream sandwich',
calories: 27,
fat: 9.0,
carbs: 37,
protein: 4.3
},
{
id: 'iD3',
name: 'Eclair',
calories: 22,
fat: 16.0,
carbs: 23,
protein: 6.0
}
]
},
getters: {
dataku: (state) => state.dataku
},
});
export default store
因为 Data props Expected Array 你已经传递了对象。
computed: {
...mapGetters(['dataku']),
}
<q-table
title="Treats"
:data="dataku"
:columns="columnss"
row-key="name"
key="key"
>
<template v-slot:body-cell-action="props">
<q-td :props="props">
<div>
<q-td key="action" :props="props">
<div class="right">
<q-btn flat scratch align="right" class="center" color="primary" icon="edit/>
<q-btn flat scratch align="right" color="primary" icon="delete"/>
</div>
</q-td>
</div>
</q-td>
</template>
</q-table>
推荐阅读
- magit - 在 magit 中,如何识别远程的默认分支?
- wix - 当我使用 /quiet 参数从 CMD 运行 wix MSI 时,它不会启动
- c++ - 如何保存数组并在 C++ 上打印它们
- csv - 为 grafana 的 influx 上传器设置带注释的 csv
- django - Django 3.1.7 模型自定义约束
- git - 如何通过 git 从意外撤消 Android Studio 中的工作中恢复?
- python-3.x - 如何使用 FTP 服务器和 django rest api 上传文件....怎么做?
- expression - 报表生成器表达式 IIF 值包含其他值
- flutter - E/MethodChannel#com.viztushar.flutter.flutter_stickers_internet/sharedata(28013):处理方法调用失败
- r - R查找由mutate()中另一列的值定义的列的值