var vm = new Vue({ el: '#app', data: { cc: '' }, methods: { ajax: function() { var _this = this; axios.get('/mock.json', {}).then(function(res) { _this.init(res); }).catch(function(res) { console.log(res); }); }, init: function(res) { this.cc = res.data.cc; } }});vm.ajax();希望頁面一開始加載完畢就發(fā)請求獲取數據,ajax函數是通過vm.ajax()進行調用的,但我不想定義vm,只按照下面的結構寫的話,能否在頁面一載入時調用ajax函數?正打算用鉤子函數試試……除此之外還有辦法嗎?
vue的初始化寫法?
米脂
2018-10-09 13:34:27