https://cn.vuejs.org/v2/guide/computed.html
// 计算属性有缓存性:如果值没有发生改变,则页面不回重新渲染
computed:{
total(){
return: this.list.length
}
}
// 默认情况下 watch 初始化时不执行
watch: {
courses(newVal, oldVal){
console.log(newVal, oldVal)
this.total = newVal.length
}
}
//
watch: {
courses: {
immediate: true, // 立即执行一次
deep: true, // 深层监听,耗性能
handler(newVal, oldVal) {
console.log(newVal, oldVal)
this.total = newVal.length
}
}
}