Vue——注意点

mode: ‘history’,//去除url中默认的#

路由跳转后,新页面不是从页面顶部

main.js

router.afterEach((to,from,next) => {
  window.scrollTo(0,0);//路由页面跳转后,新页面回到顶部
})

或者官网有在history模式下解决办法

active-class:‘active’;设置路由激活后,对应的样式;

 <router-link :to="/home" active-class="active">首页</router-link>

验证码倒计时

 <a class="number_code" @click="getCode()"> {{sendNumberCode? '获取':count+'秒'}} </a>

const TIME_COUNT = 60;
data(){
	return {
			sendNumberCode: true,
	        count: '',
	        timer: null,	
	}
},
method:{
	getCode() {
	        // 防抖
	        if (!this.timer) { //判断当前定时器是否存在,防止误点
	          this.count = TIME_COUNT;
	          this.timer = setInterval(() => {
	            this.sendNumberCode = false;
	            this.count--;
	            if (this.count < 0) {
	              clearInterval(this.timer);
	              this.sendNumberCode = true;
	            }
	          }, 1000)
	        }
	      },
	 }

vue.$set()更新数组和对象
Vue 不能检测到对象属性的添加或删除。

由于 JavaScript 的限制,Vue 不能检测以下变动的数组:

当你利用索引直接设置一个项时,例如:vm.items[indexOfItem] = newValue
当你修改数组的长度时,例如:vm.items.length = newLength

操作数组中的某项值,使用示列:this. s e t ( a r r , i n d e x , v a l ) 。 / / t h i s . set(arr, index, val)。//this. set(arr,index,val)//this.set(arr,arr[1],‘HHH’);
操作对象,使用示例:this. s e t ( o b j , k e y , v a l ) . / / t h i s . set( obj, key, val).//this. set(obj,key,val).//this.set(obj,‘age’,24);
或者通过数组的赋值,

arr1:需要操作的数组 arr2:临时数组
let arr2 = arr1.push(2);
arr1 = arr2;


 <li v-for="(item, index) in courseStatufilter" :key="index">
computed: {
      courseStatufilter() {
        //根据课程的courseStatusId 过滤
        let filterArr = new Array();
        let _currentStatuId = this.currentStatuId;//过滤的依据
        filterArr = this.courseList.filter(function (item) {
          if(_currentStatuId < 0) return item;
          return item.courseStatusId == _currentStatuId;
        })
        return filterArr;
      }
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值