VUE 开发杂货指南

前言:全文无逻辑顺序,也无关联,开发中遇到知识盲点/模糊点(当时的)有缘就来记一下

从后端到前端 ~

1、数据遍历时拿数据

<template slot-scope="scope">
       <el-button 
       		type="danger"
            @click="closeActivity(scope.row.id, scope.$index)">
            结束活动
       </el-button>
</template>

// scope.$index→拿到每一行的index
// scope.row→拿到每一行的数据

2、页面跳转以及传参取参

//页面跳转,并携带参数 id
location.href = `/createUserGroup?id=${this.groupId}`
window.open(url)
this.$router.push('/route')

//从 url 中取出参数
if(this.$route.query.id != null){   
        this.id = this.$route.query.id  //从url中那参数
        this.getUserGroup()
        }

3、单选按钮 el-radio 监听选中变化

<el-radio-group v-model="radioSex" @change="changeHandler">
    <el-radio class="radio" label="man"></el-radio>
    <el-radio class="radio" label="woman"></el-radio> 
</el-radio-group>
------------------------------------------------------------------------
methods: {
        changeHandler(value) {
            console.log('改变之后的值是:' + value)
        }
    }

4、页面刷新

//1、原始方法:
location.reload();

//2、vue自带的路由跳转:
this.$router.go(0);

5、日期格式转换

//监听定时段时间参数变化
        orderTimeChange(){
            this.form.orderTimeMin = this.orderTimes[0]
            this.form.orderTimeMax = this.orderTimes[1]
            var dateMin,dateMax;
            dateMin = new Date(this.form.orderTimeMin)
            dateMax = new Date(this.form.orderTimeMax)
            this.form.orderTimeMin = dateMin.getFullYear()+'-'+this.checkTime(dateMin.getMonth()+1)+'-'+this.checkTime(dateMin.getDate()+' '+this.checkTime(dateMin.getHours())+':'+this.checkTime(dateMin.getMinutes())+':'+this.checkTime(dateMin.getSeconds()));
            this.form.orderTimeMax = dateMax.getFullYear()+'-'+this.checkTime(dateMax.getMonth()+1)+'-'+this.checkTime(dateMax.getDate()+' '+this.checkTime(dateMax.getHours())+':'+this.checkTime(dateMax.getMinutes())+':'+this.checkTime(dateMax.getSeconds()));
        },
         checkTime(i){
            if(i<10){
            i = '0'+i
            }
            return i
            },
let timeTemp = moment(val).format('YYYY-MM-DD HH:mm:ss')
(dayjs)

6、数据不更新

this.$set(obj)
this.$set(item,'height',200)
this.$forceUpdate(obj)
this.$nextTick(()=>{……})

7、键盘监听

@keyup.enter.native = "option()" //回车键触发

import hotkeys from 'hotkeys-js'
hotkeys(
      'ctrl+z, command+z, ctrl+y, command+shift+z, ctrl+v',
      (event, handler) => {
        if (handler.key === 'ctrl+v') {
          this.paste()
        } else if (handler.key === 'ctrl+z' || handler.key === 'command+z') {
          this.$store.commit('poster/undo')
        } else {
          this.$store.commit('poster/redo')
        }
      }
    )//created
hotkeys.unbind('ctrl+z, command+z, ctrl+y, command+shift+z, ctrl+v')//destroyed()

8、组件常见的事件

// click	点击 Tag 时触发的事件
// blur	在 Input 失去焦点时触发
// focus	在 Input 获得焦点时触发
// change	仅在输入框失去焦点或用户按下回车时触发
// input	数据改变时触发
// hide	隐藏时触发
// show	显示时触发

9、数据转换

//转成两位小数的浮点数
parseFloat(str).toFixed(2) 
//字符串、数组
let str = "582563631792,582551399749,582313753586"
let arr = str.split(",")
console.log(arr) //[ '582563631792', '582551399749', '582313753586' ]
console.log(arr.join(",")) //582563631792,582551399749,582313753586
//数据深复制
newObj = JSON.parse(JSON.stringify(oldObj))

10、下一行弱校验

// eslint-disable-next-line

11、不显示滚动条滚动

element {
overflow-y: scroll;
}
element::-webkit-scrollbar {
  width: 0 !important;
}


// 优化滚动条样式
	width: 8px;
    height: 8px;
    opacity: 0;
    -webkit-transition: opacity 120ms ease-in-out;
    transition: opacity 120ms ease-in-out;

12、合并对象属性

Object.assign(target, ...sources)
将所有可枚举的属性值分配到目标对象上,若出现一样的属性名,以靠后的对象的属性值为准;

13、Boolean判断

空数组、空对象的 Boolean 值为 true ;
NaNnullundefined0false

14、鼠标悬浮时(光标)的样式

cursor : auto | crosshair | default | hand | move | help | wait | text | w-resize |s-resize | n-resize |e-resize | ne-resize |sw-resize | se-resize | nw-resize |pointer | url (url)

光标

15、css 数学计算 calc()

width: calc(100% - 50px);
//小于它父元素宽度 50px

持续更新中……

文章链接:

Vue 父子组件之间的通信传参
VUE动态加载子组件
nvm安装管理多个node.js版本
html 开发杂货指南
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

#老程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值