初学者求教,今天看到一个 Vue 对象,里面有一个单独方法,对象不都是键值对组成的嘛?为啥可以只有一个单独的方法呢? 就是下面代码里的 created(){}
代码 demo:
const app = new Vue({ el: '#app', data: { products: [] },
created() { fetch('https://api.myjson.com') .then(response => response.json()) .then(json => { this.products = json.products ) })