1、安装bootstrap
yarn add bootstrap
2、在main.js - 引入bootstrap
import "bootstrap/dist/css/bootstrap.css"
// 默认找文件夹下的index文件(但是这个不在 所以需要写路径)
3、项目解析
3.1根据id删除对应行:使用filter/splice
this.list=this.list.filter(v=>v.id!==id)
this.list.splice(id,1)
3.2阻止表单提交(刷新网页数据又回去了) 给表单点击事件添加prevent
@click.prevent
3.3给id赋值
--方法1:用时间戳
id:Date.now()//+ new Date()
--方法2:当前数组最后一个对象的id+1作为新对象id值
id: this.list[this.list.length - 1].id + 1
3.4在全局安装过滤器 moment / dayjs(轻量推荐)
3.4.1安装dayjs包
yarn add dayjs
3.4.2在main.js中导入dayjs
import dayjs from 'dayjs'
3.4.3书写全局过滤器函数--公式可以在dayjs官方文档中查找
Vue.filter('dateFormate',(oldDate)=>{
return dayjs(oldDate).format('YYYY-MM-DD')
})
3.4.4把过滤器放进样式中
{{ item.time | dateFormate }}