简体   繁体   English

日期 function 在 vue.js 中运行两次

[英]Date function runs twice in vue.js

I have written a Showdate function for my HTML blade, but last time working with it I faced with a weird situation where the code runs twice and outputs the data 2 times.我为我的 HTML 刀片编写了Showdate function,但上次使用它时遇到了一个奇怪的情况,即代码运行两次并输出数据两次。 The function worked without any problem before.The below code is inside blade: function 之前工作没有任何问题。以下代码在刀片内部:

<div v-for="day in Days">
                <p >@{{ShowDate(day.Date)}}</p>
</div>

Whenever I run the above code with Days:[{Date:"2021-03-06"},{Date:"2021-03-07"},{Date:"2021-03-08"}] console logs the below results:每当我使用Days:[{Date:"2021-03-06"},{Date:"2021-03-07"},{Date:"2021-03-08"}]运行上述代码时,控制台都会记录以下内容结果:

        2021-03-07
        2021-03-08
        2021-03-06
        2021-03-07
        2021-03-08
        2021-03-06

and this is my function:这是我的 function:

ShowDate: function(date) {
            return date
          },

You don't need this function.你不需要这个 function。 You can acces the day's Date property directly like:您可以直接访问当天的 Date 属性,例如:

<p>@{{day.Date}}</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM