【发布时间】:2020-02-03 04:49:23
【问题描述】:
我还在用 Laravel 学习这个 VueJS,我想做的是从 API 中获取类别数据并将其加载到选择下拉列表中,但是我发现这个 Axios 请求运行时间太长。
这是sn-p代码
export default {
data() {
return {
category: 0,
categories: [],
loading: true,
}
},
async created() {
let uri = '/api/getCategory';
axios.get(uri).then(response => {
this.categories = response.data;
console.log('2');
}).catch(error => console.log(error))
.finally(() => {
this.loading = false;
});
console.log('1');
},
methods: {
loadCategories() {
axios.get('/api/getCategory')
.then(response => this.categories = response.data)
.catch(error => console.log(error));
}
}
}
基于此。 1 已加载 DOM 2
有没有办法让我的 Axios API 请求在 HTML 完成加载之前先获取数据?
【问题讨论】:
-
你试过
beforeMount()钩子了吗?
标签: javascript laravel vue.js