鍍金池/ 問答/HTML/ vue SPA渲染前處理

vue SPA渲染前處理

現(xiàn)在有個需求是SPA渲染前需要發(fā)一個異步請求,再進行渲染,現(xiàn)在比較挫的方法是:

//main.js

loginInit(
    () => {
        new Vue({
            el: "#app",
            router,
            store,
            render: h => h(App)
        })
    }
);

function loginInit(callback) {
    axios({
            method: "post",
            url: "xxx",
            data: {},
            timeout: 1000,
            responseType: "json"
        })
        .then(response => {
            //一些處理
            callback();
        })
        .catch(error => {
            callback();
        });
}

請問有沒有優(yōu)雅一點的辦法?

回答
編輯回答
裸橙

用腳手架吧,在鉤子函數(shù)created()里面寫請求

2017年4月10日 00:14