Moh*_*our 5 date laravel vue.js laravel-5 vuejs2
我正在使用 Verta 库将 Laravel 中的公历日期转换为回历日期 https://github.com/hekmatinasser/verta
在简单模式(.blade.php 文件)中,我使用如下代码:
{{ Verta($category->created_at)->format('%d %B %Y') }}
for converting {{created_at}}
Run Code Online (Sandbox Code Playgroud)
但在 Vue js 中我无法访问这种格式
{{category.created_at}}
Run Code Online (Sandbox Code Playgroud)
如何使用此方法转换 vue js 日期?
简单地说,您可以通过 moment.js 按照三个步骤来完成。
步骤1:
npm install moment --save
Run Code Online (Sandbox Code Playgroud)
第2步:
import moment from "moment";
Run Code Online (Sandbox Code Playgroud)
步骤3:
export default {
data() {
return {
moment: moment
}
} }
Run Code Online (Sandbox Code Playgroud)
完毕。
现在在下面做
{{ moment(category.created_at).format("DD-MM-YYYY") }}
Run Code Online (Sandbox Code Playgroud)
您可以在模型上使用变元来解析日期,然后再返回它。
public function getCreatedAtAttribute($value)
{
return Verta($value)->format('%d %B %Y');
}
Run Code Online (Sandbox Code Playgroud)
这应该在您的类别模型中定义
{{category.created_at}}
Run Code Online (Sandbox Code Playgroud)
然后将包含已经解析的日期
| 归档时间: |
|
| 查看次数: |
11659 次 |
| 最近记录: |