laravel - 将碳日期作为道具传递将在 vue 模板中返回计算
问题描述
我想问一下你是怎么解决这个问题的
:birthdate="{{ $user->profile->birthdate->format('m-d-Y') }}"
在我的模型中我有这个
/**
* The attributes that should be cast to native types.
*
* @var array
*//**
*/
protected $dates = [
'birthdate',
];
我想在我的 vue 模板中将它作为道具传递
props : {
birthdate : {
type : String,
required : true ,
default : null
}
}
但相反,我得到一个取决于道具的计算。只要看看我告诉过你的 :birthdate 道具,如果我把它像 m/d/Y 一样,它会分割整个事物,所以如果它像12/21/2019
它会分割它,如果它是就像12-21-2019
它在 vue 模板上传递时会减去整个东西
解决方案
尝试删除vue绑定:
并将其用作:
birthdate="{{ $user->profile->birthdate->format('m-d-Y') }}"
或保留:
但将您的字符串用单引号括起来。
:birthdate="'{{ $user->profile->birthdate->format('m-d-Y') }}'"
或者赋值给一个变量
:birthdate="myVar"
data(){
return{ myVar: "{{ $user->profile->birthdate->format('m-d-Y') }}"};
}
因为:
orv-bind
需要表达式/变量,所以当您从 PHP{{ $user->profile->birthdate->format('m-d-Y') }}
中回显时, 12-21-2019
vue 会将减法视为整数而不是字符串。
推荐阅读
- angular - 如何以角度访问多个树的项目?
- c# - 实体框架核心加入并包含内部实体
- php - 在mysql数据库中插入一条记录后,如何使用ajax监听器显示通知?
- rest - 用户特定资源的 ETag
- uwp - 如何在 UWP 中获取 CollectionViewSource.View.Count 的更新
- spring - 从网络向模型添加参数
- javascript - reactjs - 在 npm run build 得到 Uncaught TypeError: Super expression must be null or a function之后
- ios - 如何在 iOS swift 中将蓝牙数据写入苹果健康套件
- c++ - 更改 0 以获得 1 的最大序列
- ios - 连接外部键盘时如何显示iphone虚拟键盘