mounted()
方法和data()
和methods
是同级别的
<script>
export default {
name: 'app',
data() {
return {
todo: '',
list: []
}
},
methods: {
},
// 生命周期函数 页面刷新时调用
mounted() {
//取出缓存 因为存入的时候用JSON序列化了,所以取要反序列化
var list = JSON.parse(localStorage.getItem('list'));
if (list) {
this.list = list;
}
}
}
</script>