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;
}
},