【精准扶贫JS】我的健忘症弥补区域

1、编辑回传时间

editHandle(id) {
     getNoticeById(id).then(res => {
         this.$nextTick(()=>{
             this.editInfo = Object.assign({},res.data) ;
             if (this.editInfo.noticeType==2) {
                 this.editInfo.startDatetime = String(new Date(this.editInfo.startDatetime));
                 this.editInfo.endDatetime = String(new Date(this.editInfo.endDatetime));
             }
         })
         this.platformAddDialog = true;
     }).catch(err => {
         this.$message.error(err.message || '请求公告信息失败')
     })
 },

2、多选提取某一项变数组

handleSelectionChange(val) {
    this.multipleSelection = val.map(item => item.id) ; 
},

3、删除和批量删除使用一个函数

// 批量删除
deletesHandle() {
    this.delFunction(this.multipleSelection);
},
// 删除
deleteHandle(id) {
    let ids = [id]
    this.delFunction(ids)
},
// del Function
delFunction(ids) {
    this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
        delNoticeByIds(ids).then(res => {
           if(res.state == 0) {
               this.$message.success(res.message || '删除成功');
               this.getList()
           } else {
               this.$message.error(res.message || '删除失败')
           }
       }).catch(err => {
           this.$message.error(err.message || '删除失败')
       })
    }).catch(()=>{
        this.$message.success( '取消删除')
    })
    this.getList()
},

4、watch多种写法

watch: {
        editInfo: {
            handler : function (val) {
                if(val == null) {
                   this.resetForm('addForm'); 
                }
                this.addForm.realName = val == null ? '' : val.realName;
                this.addForm.fieldLabel = val == null ? '' : val.fieldLabel;
                this.addForm.industryLabel = val == null ? [] : (val.industryLabel && val.industryLabel.length > 0 ? val.industryLabel.split(',') : []);
               if(this.addForm.fieldLabel && this.addForm.fieldLabel.length > 0) {
                    this.getIndustryList(this.addForm.fieldLabel);
                }
            }
        },
        'addForm.fieldLabel'(val) {
            if(val && val.length > 0) {
                this.getIndustryList(val);
            }
        }
    }

5、标准时间 转 yyyy-MM-dd HH:mm:ss格式
A

startTime: this.YymmddFormat(this.addParamForm.startTime)
YymmddFormat(newDate) {
    let Month = newDate.getMonth() + 1;
    Month = Month >= 10 ? Month : '0' + Month;
    let d = newDate.getDate();
    d = d >= 10 ? d : '0' + d
    return [
        [newDate.getFullYear(), Month, d].join('-'), [newDate.getHours(), newDate.getMinutes(), newDate.getSeconds()].join(':')
    ].join(' ');
},

B

let date =  new Date(
     new Date().getFullYear(),
     new Date().getMonth() - 1,
     new Date().getDate()
 );
 let time = this.YymmddFormat(date)
YymmddFormat(newDate) {
    let Month = newDate.getMonth() + 1;
    Month = Month >= 10 ? Month : '0' + Month;
    let d = newDate.getDate();
    d = d >= 10 ? d : '0' + d
    return [
        [newDate.getFullYear(), Month, d].join('-')
    ].join(' ');
},

6、将字符串A替换成字符串B

let reg=new RegExp('<img','g') 
content=content.replace(reg,'<img style="max-width:100%;height:auto;" ');

7、时间选择器禁止选择今天之后

<el-date-picker  v-model="timeValue" type="date" placeholder="选择查看日期" :picker-options="pickerOptions"></el-date-picker>
...
	  data() {
            return {
                timeValue:'',
                pickerOptions:{
                    disabledDate(time) {
                        return time.getTime() >= (Date.now() - (24*60*60*1000))
                    }
                },
            }
        },

8、数组变了但页面不渲染(数组改变太深)

// 把数组转换成json然后再转换回来
vm.arr=JSON.parse(JSON.stringify(vm.arr));

9、一选择器改变值后二选择器自动清空
在这里插入图片描述

可编辑表格中有两个选择器,第一个select选择器,选择项变化时,清空第二个select选择器选择项并请求第二个选择器下拉列表数据,当做出清空选择器绑定数据后,第二个选择器下拉项无法选择
利用this.$set替换直接赋值

selectChange(val){
    // form.postId = null   
    this.$set(this.form, 'postId', null)
}

10、截取字符串

let str = 'abcdef';
// 0
str = str.slice(0);//返回整个字符串 abcdef
str = str.substring(0);//返回整个字符串 abcdef
str = str.substr(0);//返回整个字符串 abcdef
// 使用一个参数
str = str.slice(2);//截取第二个之后所有的字符 cdef 即从第三位开始
str = str.substring(2);//截取第二个之后所有的字符 cdef
str = str.substr(2);//截取第二个之后所有的字符 cdef
 
// 使用两个参数
str = str.slice(2,4);//截取第二个到第四个之间的字符 cd
str = str.substring(2,4);//截取第二个到第四个之间的字符 cd
str = str.substr(2,4);//截取从第3个开始往后数4位之间的字符 cdef
 
// 使用两个负数
str = str.slice(1,-3);//截取第二个到第四个之间的字符 bc
str = str.substring(1,-3);//截取第二个到第四个之间的字符 a #负数转换为0
str = str.substr(1,-3);//不能为负数,若强行传递负数,会被当成0处理 ' ' #负数转换为0

console.log(str)

11、父组件值变子组件不能及时渲染:使用v-if销毁重置

在这里插入图片描述
12、列表按照整改期限进行排序

const showList = list.sort((item, item1) => {
       return item1.rectificationLimit - item.rectificationLimit;
});
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值