子组件道具的计算属性 [英] Computed property on child component props

查看:19
本文介绍了子组件道具的计算属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的设置,我有子组件道具,里面有日期时间格式,我想在我的表中将其更改为更易读的格式,所以我使用 moment js 来更改格式并执行这些类型对于任务,如果我使用计算属性会更有意义.在我的 index.vue 中像这样

<div class="page-content"><div class="content-wrapper"><数据查看器 :source="source" :thead="thead"><模板范围=道具"><tr><td>{{props.item.name}}</td><td>{{props.item.creator}}</td><td><i class="icon-checkmark5" v-if="props.item.publish === '0'"></i><i class="icon-cancel-circle2" v-else></i>{{props.item.publish}}//用于测试目的以查看返回值</td><td>{{publishDate}}</td>//这是我把我的计算更改为created_at格式的地方</tr></模板></数据查看器>

<script type="text/javascript">从'../../components/dataviewer.vue'导入DataViewer从时刻"导入时刻导出默认{成分:{数据查看器},数据(){返回{来源:'/api/article',头:[{title: 'Name', key: 'name', sort: true},{title: 'Creator', key: 'creator_id', sort: true},{title: 'Publish', key: 'publish', sort: true},{title: 'Created', key: 'created_at', sort: true}],}},计算:{发布日期:函数(){return moment(props.item.created_at).format('YYYY-MM-DD')}}}

这是我的数据查看器文件中的内容