输出的结果是没有任何问题的,但是浏览器就是会报这个错误 <template> <div> <ul v-if="data.length>0"> <li v-for="item in data" :key="item.id"> <div class="foot_title" v-html="dateFormat(item.time)"></div> <div class="foot_list" v-for="list in item.commodityList" :key="list.id"> <div class="foot_desc"> <div>{{list.productName}}</div> </div> </div> </li> </ul> <div v-else class="no-collect"> <p>暂无浏览历史~</p> </div> </div> js部分:data () { return { data: [ {time: '07/16', commodityList: [ {productName: '苹果'}, {productName: '苹果'} ] }, {time: '07/13', commodityList: [ {productName: '雪梨'}, {productName: '雪梨'} ] }, {time: '07/12', commodityList: [ {productName: '西瓜'}, {productName: '西瓜'} ] } ], titleText: '今天' } }, methods: { dateFormat (val = '') { let myDate = new Date() // 获取系统当前时间 let day1 = new Date(val) let day2 = new Date(myDate.getMonth() + 1 + '/' + myDate.getDate()) const number = (day2 - day1) / (1000 * 60 * 60 * 24) if (number === 0) { //问题出在这里!!! this.titleText = '今天' } else if (number === 1) { this.titleText = '昨天' } else { this.titleText = val console.log(number) } return this.titleText } }
亲 解决了吗